discourse/app/jobs
Alan Guo Xiang Tan 7c321d3aad
PERF: Update `Group#user_count` counter cache outside DB transaction (#19256)
While load testing our user creation code path in production, we
identified that executing the DB statement to update the `Group#user_count` column within a
transaction is creating a bottleneck for us. This is because the
creation of a user and addition of the user to the relevant groups are
done in a transaction. When we execute the DB statement to update
`Group#user_count` for the relevant group, a row level lock is held
until the transaction completes. This row level lock acts like a global
lock when the server is creating users that will be added to the same
group in quick succession.

Instead of updating the counter cache within a transaction which the
default ActiveRecord `counter_cache` option does, we simply update the
counter cache outside of the committing transaction.

Co-authored-by: Rafael dos Santos Silva <xfalcox@gmail.com>

Co-authored-by: Rafael dos Santos Silva <xfalcox@gmail.com>
2022-11-30 11:52:08 -03:00
..
concerns DEV: enable frozen string literal on all files 2019-05-13 09:31:32 +08:00
onceoff DEV: Quote values when constructing SQL (#18827) 2022-11-01 14:05:13 -05:00
regular PERF: Update `Group#user_count` counter cache outside DB transaction (#19256) 2022-11-30 11:52:08 -03:00
scheduled DEV: Quote values when constructing SQL (#18827) 2022-11-01 14:05:13 -05:00
base.rb FIX: Uninitialized class variable error in sidekiq (#17227) 2022-06-24 14:17:39 +10:00