Skip to content

Commit

Permalink
fix in_batches
Browse files Browse the repository at this point in the history
  • Loading branch information
tycooon committed Dec 10, 2024
1 parent 9d94378 commit 620a36a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions lib/sequel/extensions/batches/yielder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ def call
base_ds = setup_base_ds or return
return enum_for(:call) unless block_given?

current_instance = nil
current_pk = nil

loop do
working_ds =
if current_instance
base_ds.where(generate_conditions(current_instance.to_h, sign: sign_from_exclusive))
if current_pk
base_ds.where(generate_conditions(current_pk.to_h, sign: sign_from_exclusive))
else
base_ds
end

working_ds_pk = working_ds.select(*qualified_pk).order(*order_by(qualified: true)).limit(of)
current_instance = db.from(working_ds_pk).select(*pk).order(*order_by).last or break
working_ds = working_ds.where(generate_conditions(current_instance.to_h, sign: sign_to_inclusive))
current_pk = db.from(working_ds_pk).select(*pk).order(*order_by).last or break
working_ds = working_ds.where(generate_conditions(current_pk.to_h, sign: sign_to_inclusive))

yield working_ds
end
Expand Down Expand Up @@ -94,7 +94,7 @@ def generate_conditions(input_pk, sign:)
end

def setup_base_ds
base_ds = ds.order(*order_by(qualified: true))
base_ds = ds
base_ds = base_ds.where(generate_conditions(check_pk(start), sign: sign_from_inclusive)) if start
base_ds = base_ds.where(generate_conditions(check_pk(finish), sign: sign_to_inclusive)) if finish

Expand All @@ -105,7 +105,8 @@ def setup_base_ds
return unless actual_start && actual_finish

base_ds = base_ds.where(generate_conditions(actual_start, sign: sign_from_inclusive))
base_ds.where(generate_conditions(actual_finish, sign: sign_to_inclusive))
base_ds = base_ds.where(generate_conditions(actual_finish, sign: sign_to_inclusive))
base_ds.order(*order_by(qualified: true))
end
end
end
2 changes: 1 addition & 1 deletion sequel-batches.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |spec|
spec.name = "sequel-batches"
spec.version = "2.0.2"
spec.version = "2.0.3"
spec.authors = %w[fiscal-cliff umbrellio]
spec.email = ["[email protected]"]
spec.required_ruby_version = ">= 3.0"
Expand Down

0 comments on commit 620a36a

Please sign in to comment.