mirror of
https://github.com/discourse/discourse.git
synced 2026-07-31 16:48:26 -05:00
Why this change? The test was randomly failing in https://github.com/discourse/discourse/actions/runs/6936264158/job/18868087113 with the following failure: ``` expect do user.update_ip_address!("127.0.0.1") end.to change { UserIpAddressHistory.where(user_id: user.id).count }.by(1) expected `UserIpAddressHistory.where(user_id: user.id).count` to have changed by 1, but was changed by 0 ``` This is due to the fact that ActiveRecord will actually cache the result of `UserIpAddressHistory.where(user_id: user.id).count`. However, `User.update_ip_address!` relies on mini_sql and does not go through ActiveRecord. As a result, the query cache is not cleared and hence the flakiness. What does this change do? This change uses the `uncached` method provided by ActiveRecord when we are fetching the count.