From fdd150ebee099f7f38a9481bcf71515d196bba65 Mon Sep 17 00:00:00 2001 From: KirIgor Date: Fri, 17 May 2024 18:12:55 +0600 Subject: [PATCH] review ffixes --- lib/umbrellio_utils/database.rb | 10 +++------- spec/umbrellio_utils/database_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/umbrellio_utils/database.rb b/lib/umbrellio_utils/database.rb index 086b354..e15bceb 100644 --- a/lib/umbrellio_utils/database.rb +++ b/lib/umbrellio_utils/database.rb @@ -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) @@ -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) @@ -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) diff --git a/spec/umbrellio_utils/database_spec.rb b/spec/umbrellio_utils/database_spec.rb index a74f411..09fb354 100644 --- a/spec/umbrellio_utils/database_spec.rb +++ b/spec/umbrellio_utils/database_spec.rb @@ -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 = [] @@ -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