betterplace/acts_as_account — pull request #1 by jbran (2012-09-22 01:26:46+00:00)
Title: Use update_counters to solve concurrency issues.

Hi,

At https://github.com/rallysf/acts_as_account, we noticed our account.postings_count and account.balance differing from the sum of our postings for that account and the postings sum respectively. In examining the issue, we found that it was a concurrency issue when an account received multiple postings. Previously, the lock on the account rows were being undone by the use of .reload.

In testing locally, using ab with varying concurrency levels, we found that both update_counters and just removing the .reload both resulted in proper accounting between the postings and the account's view of those postings. I viewed the account's balances as being treated like other counters in rails, thus the use of update_counters in this change.