Open
Description
Problem
Currently, when using counter_culture to fix counts, all read operations (including counting records) happen on the primary database. This can cause significant lock contentions and performance issues, especially when running counter_culture_fix_counts in background jobs with large datasets.
Current Workaround
We currently have to explicitly specify using read replicas for each counter_culture_fix_counts call:
Model.counter_culture_fix_counts(
db_connection_builder: proc { |reading, block|
if reading
ApplicationRecord.connected_to(role: :reading, &block)
else
ApplicationRecord.connected_to(role: :writing, &block)
end
}
)
I was thinking something along these lines
# In initializer
CounterCulture.configure do |config|
config.use_read_replica = true
end
# Or as a default option in counter_culture itself
Apologies for asking if this feature already exists
Metadata
Assignees
Labels
No labels