ankane / distribute_reads

Scale database reads to replicas in Rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

distribute_reads not query from replica when query has bracket

icecold21 opened this issue · comments

Hi Ankane, great gem btw,

I was wondering why query which has bracket arounds it goes to primary instead of replica.
These are code to repro the issue:

Query to replica

distribute_reads do
  ActiveRecord::Base.connection.execute("SELECT 1")
end

Query to primary

distribute_reads do
  ActiveRecord::Base.connection.execute("(SELECT 1)")
end

Hey @icecold21, Makara uses regular expressions to determine which queries can go to replicas. You can force the query to use a replica with distribute_reads(replica: true).

Hi @ankane, thanks for the answer. I'll go ahead and close this issue.