|
|
|
|
|
by drdaeman
459 days ago
|
|
In your code, in the `ensure` part you want `SET synchronous_commit TO DEFAULT` instead of the explicit `on` (https://www.postgresql.org/docs/current/sql-set.html) Then, I suspect you may probably rather want to use `SET LOCAL` rather than just `SET`, so it applies to a single transaction only. So maybe something more like def asynchronous_transaction(&block)
ActiveRecord::Base.connection.transaction do
ActiveRecord::Base.connection.execute("SET LOCAL synchronous_commit = off")
yield
end
end
Please note that I don't really know Rails (in particular, I've no idea whenever `Base.connection` is guaranteed to be exactly the same throughout this function's lifecycle or if e.g. there's a connection pool underneath), so I could be introducing some subtle bugs here. |
|