summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Stark <stark@gitlab.com>2018-01-06 14:53:16 +0000
committerGreg Stark <stark@gitlab.com>2018-01-06 14:56:05 +0000
commitb230cf8e1f0a76edc97407123574e4c20eb2efa5 (patch)
treed2df075a57a9b66beb1cddf360adf04820070cb6
parentfb583c4b1839af16c50e27105a300695aa50bcad (diff)
downloadgitlab-ce-each-batch-for-batch-size-one.tar.gz
Special case batch size 1 to avoid doing needless range lookupseach-batch-for-batch-size-one
-rw-r--r--app/models/concerns/each_batch.rb15
1 files changed, 8 insertions, 7 deletions
diff --git a/app/models/concerns/each_batch.rb b/app/models/concerns/each_batch.rb
index 6ddbb8da1a9..b6a106ed883 100644
--- a/app/models/concerns/each_batch.rb
+++ b/app/models/concerns/each_batch.rb
@@ -62,19 +62,20 @@ module EachBatch
.limit(1)
.take
- relation = where(arel_table[column].gteq(start_id))
-
- if stop
- stop_id = stop[column]
- start_id = stop_id
- relation = relation.where(arel_table[column].lt(stop_id))
+ if (of == 1)
+ relation = where(arel_table[column].eq(start_id))
+ else if stop
+ relation = where(arel_table[column].gteq(start_id)).where(arel_table[column].lt(stop[column])
+ else
+ relation = where(arel_table[column].gteq(start_id))
end
-
+
# Any ORDER BYs are useless for this relation and can lead to less
# efficient UPDATE queries, hence we get rid of it.
yield relation.except(:order), index
break unless stop
+ start_id = stop[column]
end
end
end