Skip to content

Commit

Permalink
review ffixes
Browse files Browse the repository at this point in the history
  • Loading branch information
KirIgor committed May 17, 2024
1 parent 72692ab commit fdd150e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 3 additions & 7 deletions lib/umbrellio_utils/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def each_record(dataset, **options, &block)

with_temp_table(dataset, **options) do |ids|
if primary_key.size > 1
where_expr = Sequel.|(*ids.map { |id| complex_key_expr(primary_key, id) })
where_expr = Sequel.|(*ids.map { |id| row(primary_key) =~ row(id.values) })
dataset.model.where(where_expr).reverse(row(primary_key)).each(&block)
else
dataset.model.where(primary_key => ids).reverse(primary_key).each(&block)
Expand Down Expand Up @@ -85,8 +85,8 @@ def create_temp_table(dataset, **options)

private

def row(primary_key)
Sequel.function(:row, *primary_key)
def row(values)
Sequel.function(:row, *values)
end

def primary_key_from(**options)
Expand All @@ -108,10 +108,6 @@ def sleep_interval_from(sleep)
end
end

def complex_key_expr(primary_key, record)
primary_key.to_h { |field| [field, record[field]] }
end

def pop_next_pk_batch(temp_table_name, primary_key, batch_size)
row = row(primary_key)
pk_expr = DB[temp_table_name].select(*primary_key).reverse(row).limit(batch_size)
Expand Down
4 changes: 2 additions & 2 deletions spec/umbrellio_utils/database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
Array.new(10) { |index| Hash[geo: "Europe #{index + 1}", nick: "user#{index + 1}"] }
end

let(:reversed_nicks) { complex_users_data.pluck(:nick).reverse }
let(:nicks) { complex_users_data.pluck(:nick) }

subject(:result_nicks) do
users = []
Expand All @@ -76,7 +76,7 @@
end

it "yields all records" do
expect(result_nicks).to match_array(reversed_nicks)
expect(result_nicks).to match_array(nicks)
expect(sleep_calls).to eq([])
end
end
Expand Down

0 comments on commit fdd150e

Please sign in to comment.