@@ -21,19 +21,19 @@ def call
21
21
base_ds = setup_base_ds or return
22
22
return enum_for ( :call ) unless block_given?
23
23
24
- current_instance = nil
24
+ current_pk = nil
25
25
26
26
loop do
27
27
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 ) )
30
30
else
31
31
base_ds
32
32
end
33
33
34
34
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 ) )
37
37
38
38
yield working_ds
39
39
end
@@ -94,7 +94,7 @@ def generate_conditions(input_pk, sign:)
94
94
end
95
95
96
96
def setup_base_ds
97
- base_ds = ds . order ( * order_by ( qualified : true ) )
97
+ base_ds = ds
98
98
base_ds = base_ds . where ( generate_conditions ( check_pk ( start ) , sign : sign_from_inclusive ) ) if start
99
99
base_ds = base_ds . where ( generate_conditions ( check_pk ( finish ) , sign : sign_to_inclusive ) ) if finish
100
100
@@ -105,7 +105,8 @@ def setup_base_ds
105
105
return unless actual_start && actual_finish
106
106
107
107
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 ) )
109
110
end
110
111
end
111
112
end
0 commit comments