Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add option to use read replicas by default for count operations #403

Open
ashishra0 opened this issue Dec 23, 2024 · 0 comments

Comments

@ashishra0
Copy link

ashishra0 commented Dec 23, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant