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
In database cluster setups where reading and writing are separated, Laravel offers useWritePdo() method on the query builder to execute a read (select) query against the primary (write) database server, all writing queries will be routed there automatically
There are methods like firstOrCreate() that combine reading and writing and the second depends on the former. If you make two firstOrCreate() calls at the same time, you are likely to create two duplicate records because SELECTs were done against the read replica that naturally has a small lag (latency).
As a result, one has to add useWritePdo()->firstOrCreate() to the chain pretty much every time because it doesn't make sense not doing it. However, it's easy to forget about it and end up having duplicate entries in the database.
I propose that useWritePdo() should be applied automatically when dual (read-write) methods like firstOrCreate() are called
Before making a pull request, I would like to hear more opinions
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In database cluster setups where reading and writing are separated, Laravel offers useWritePdo() method on the query builder to execute a read (select) query against the primary (write) database server, all writing queries will be routed there automatically
There are methods like firstOrCreate() that combine reading and writing and the second depends on the former. If you make two firstOrCreate() calls at the same time, you are likely to create two duplicate records because SELECTs were done against the read replica that naturally has a small lag (latency).
As a result, one has to add useWritePdo()->firstOrCreate() to the chain pretty much every time because it doesn't make sense not doing it. However, it's easy to forget about it and end up having duplicate entries in the database.
I propose that useWritePdo() should be applied automatically when dual (read-write) methods like firstOrCreate() are called
Before making a pull request, I would like to hear more opinions
Beta Was this translation helpful? Give feedback.
All reactions