Skip to content

Commit 620a36a

Browse files
committed
fix in_batches
1 parent 9d94378 commit 620a36a

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

lib/sequel/extensions/batches/yielder.rb

+8-7
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ def call
2121
base_ds = setup_base_ds or return
2222
return enum_for(:call) unless block_given?
2323

24-
current_instance = nil
24+
current_pk = nil
2525

2626
loop do
2727
working_ds =
28-
if current_instance
29-
base_ds.where(generate_conditions(current_instance.to_h, sign: sign_from_exclusive))
28+
if current_pk
29+
base_ds.where(generate_conditions(current_pk.to_h, sign: sign_from_exclusive))
3030
else
3131
base_ds
3232
end
3333

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

3838
yield working_ds
3939
end
@@ -94,7 +94,7 @@ def generate_conditions(input_pk, sign:)
9494
end
9595

9696
def setup_base_ds
97-
base_ds = ds.order(*order_by(qualified: true))
97+
base_ds = ds
9898
base_ds = base_ds.where(generate_conditions(check_pk(start), sign: sign_from_inclusive)) if start
9999
base_ds = base_ds.where(generate_conditions(check_pk(finish), sign: sign_to_inclusive)) if finish
100100

@@ -105,7 +105,8 @@ def setup_base_ds
105105
return unless actual_start && actual_finish
106106

107107
base_ds = base_ds.where(generate_conditions(actual_start, sign: sign_from_inclusive))
108-
base_ds.where(generate_conditions(actual_finish, sign: sign_to_inclusive))
108+
base_ds = base_ds.where(generate_conditions(actual_finish, sign: sign_to_inclusive))
109+
base_ds.order(*order_by(qualified: true))
109110
end
110111
end
111112
end

sequel-batches.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
55

66
Gem::Specification.new do |spec|
77
spec.name = "sequel-batches"
8-
spec.version = "2.0.2"
8+
spec.version = "2.0.3"
99
spec.authors = %w[fiscal-cliff umbrellio]
1010
spec.email = ["oss@umbrellio.biz"]
1111
spec.required_ruby_version = ">= 3.0"

0 commit comments

Comments
 (0)