This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from gitlab/spec/support/matchers/exceed_query_limit.rb | |
RSpec::Matchers.define :exceed_query_limit do |expected| | |
supports_block_expectations | |
match do |block| | |
@subject_block = block | |
actual_count > expected_count + threshold | |
end | |
failure_message_when_negated do |actual| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
i.relname AS index_name, | |
t.relname AS table_name, | |
s.idx_scan AS times_used, | |
pg_size_pretty(pg_relation_size(i.oid)) AS index_size | |
FROM | |
pg_stat_user_indexes s | |
JOIN | |
pg_index ix | |
ON |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord | |
class Relation | |
def pluck_in_batches(*columns, batch_size: 1000, start: nil) | |
relation = self | |
relation = relation.where(table[primary_key].gteq(start)) if start | |
batch_order = "#{table.name}.#{primary_key} ASC" | |
relation = relation.reorder(batch_order) | |
loop do | |
batch = relation.limit(batch_size).pluck(*columns, primary_key) |