You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello. Thank you for all your work on this awesome gem. I have a question about using Octopus with replication (with fully_replicated: false).
If I instantiate a User using the master shard, then all queries for associations go to the master, even if I try to force queries to the read slave. Here's an example (in this app, a user has_many questions):
u = User.first # fetches from master by default
q = Octopus.using(:read_slave) do
u.questions.to_a # sends query to master, but I want it to go to the read slave
end
I would like to be able to fetch the questions from the :read_slave. There are a few ways I see to accomplish this. I can avoid using the ORM:
u = User.first
q = Octopus.using(:read_slave) do
Question.where(user_id: u.id).to_a
end
Or I can reload the user using the read slave:
u = User.first
q = Octopus.using(:read_slave) do
user_read_only = User.find(u.id)
user_read_only.questions.to_a
end
The first solution is ugly for complicated queries and the second requires an extra trip to the database. Is there a nicer way that I'm missing, or could I monkey-patch this functionality into Octopus?
The text was updated successfully, but these errors were encountered:
Hello. Thank you for all your work on this awesome gem. I have a question about using Octopus with replication (with
fully_replicated: false
).If I instantiate a
User
using the master shard, then all queries for associations go to the master, even if I try to force queries to the read slave. Here's an example (in this app, a userhas_many
questions):I would like to be able to fetch the questions from the
:read_slave
. There are a few ways I see to accomplish this. I can avoid using the ORM:Or I can reload the user using the read slave:
The first solution is ugly for complicated queries and the second requires an extra trip to the database. Is there a nicer way that I'm missing, or could I monkey-patch this functionality into Octopus?
The text was updated successfully, but these errors were encountered: