Fix budget cache invalidation after transaction deletion (#2808)

Signed-off-by: Juan José Mata <juanjo.mata@gmail.com>
Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
Sure Admin (bot)
2026-08-25 04:02:01 +02:00
committed by GitHub
co-authored by Juan José Mata
parent 3e79de5b64
commit 311f06e404
2 changed files with 23 additions and 4 deletions
+1 -4
View File
@@ -493,10 +493,7 @@ class Family < ApplicationRecord
# Used for invalidating entry related aggregation queries
def entries_cache_version
@entries_cache_version ||= begin
ts = entries.maximum(:updated_at)
ts.present? ? ts.to_i : 0
end
"#{entries.count}-#{entries.maximum(:updated_at)&.to_f || 0}"
end
# Used for invalidating caches keyed on entries (e.g. the transactions
+22
View File
@@ -165,6 +165,28 @@ class FamilyTest < ActiveSupport::TestCase
assert_equal "Groups", family.moniker_label_plural
end
test "entries_cache_version changes when an older entry is destroyed" do
family = families(:dylan_family)
newer_entry = entries(:transaction)
older_entry = Entry.create!(
account: accounts(:depository),
entryable: Transaction.create!(category: categories(:food_and_drink)),
date: Date.current,
name: "Older duplicate",
amount: 42,
currency: "USD",
created_at: 2.days.ago,
updated_at: 2.days.ago
)
newer_entry.update!(updated_at: 1.day.ago)
before_destroy = family.reload.entries_cache_version
older_entry.destroy!
assert_not_equal before_destroy, family.reload.entries_cache_version
end
test "default currency comes from country ISO data" do
assert_equal "CAD", Family.default_currency_for_country("CA")
assert_equal "EUR", Family.default_currency_for_country("DE")