From 427fe31eec9de58634d149af88032e140ed6c172 Mon Sep 17 00:00:00 2001 From: maximerety Date: Mon, 26 Feb 2024 09:36:57 +0100 Subject: [PATCH] Select primary keys instead of full records It can help performance by avoiding table lookups and reducing network usage. --- lib/safe-pg-migrations/helpers/batch_over.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/safe-pg-migrations/helpers/batch_over.rb b/lib/safe-pg-migrations/helpers/batch_over.rb index d256b8ec..8d5ffb45 100644 --- a/lib/safe-pg-migrations/helpers/batch_over.rb +++ b/lib/safe-pg-migrations/helpers/batch_over.rb @@ -19,11 +19,11 @@ def each_batch def next_batch return if endless? - first = next_scope.take + first = next_scope.select(primary_key).take return unless first - last = next_scope.offset(@of).take + last = next_scope.select(primary_key).offset(@of).take first_key = first[primary_key] last_key = last.nil? ? nil : last[primary_key]