Cache user social credits on profile

This commit is contained in:
2025-08-22 22:28:48 +08:00
parent d1c3610ec8
commit 8f3825e92c
4 changed files with 30 additions and 2 deletions

View File

@@ -18,6 +18,13 @@ public class SocialCreditService(AppDatabase db, ICacheService cache)
};
db.SocialCreditRecords.Add(record);
await db.SaveChangesAsync();
await db.AccountProfiles
.Where(p => p.AccountId == accountId)
.ExecuteUpdateAsync(p => p.SetProperty(v => v.SocialCredits, v => v.SocialCredits + record.Delta));
await cache.RemoveAsync($"{CacheKeyPrefix}{accountId}");
return record;
}
@@ -32,6 +39,7 @@ public class SocialCreditService(AppDatabase db, ICacheService cache)
.Where(x => x.AccountId == accountId)
.SumAsync(x => x.Delta);
records += BaseSocialCredit;
await cache.SetAsync($"{CacheKeyPrefix}{accountId}", records);
return records;
}