🐛 Trying to fix poll answer cache

This commit is contained in:
2025-08-06 02:59:17 +08:00
parent b0af3af059
commit a52b09b787
2 changed files with 13 additions and 10 deletions

View File

@@ -60,5 +60,5 @@ public class PollAnswer : ModelBase
public Guid AccountId { get; set; }
public Guid PollId { get; set; }
[JsonIgnore] public Poll Poll { get; set; } = null!;
[JsonIgnore] public Poll? Poll { get; set; }
}

View File

@@ -51,7 +51,10 @@ public class PollService(AppDatabase db, ICacheService cache)
var answer = await db.PollAnswers
.Where(e => e.PollId == pollId && e.AccountId == accountId)
.AsNoTracking()
.FirstOrDefaultAsync();
if (answer is not null)
answer.Poll = null;
// Set the answer even it is null, which stands for unanswered
await cache.SetAsync(cacheKey, answer, TimeSpan.FromMinutes(30));