🐛 Trying to fix poll answer cache
This commit is contained in:
@@ -10,12 +10,12 @@ public class Poll : ModelBase
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public List<PollQuestion> Questions { get; set; } = new();
|
||||
|
||||
|
||||
[MaxLength(1024)] public string? Title { get; set; }
|
||||
[MaxLength(4096)] public string? Description { get; set; }
|
||||
|
||||
|
||||
public Instant? EndedAt { get; set; }
|
||||
|
||||
|
||||
public Guid PublisherId { get; set; }
|
||||
[JsonIgnore] public Publisher.Publisher? Publisher { get; set; }
|
||||
}
|
||||
@@ -32,15 +32,15 @@ public enum PollQuestionType
|
||||
public class PollQuestion : ModelBase
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
|
||||
public PollQuestionType Type { get; set; }
|
||||
[Column(TypeName = "jsonb")] public List<PollOption>? Options { get; set; }
|
||||
|
||||
|
||||
[MaxLength(1024)] public string Title { get; set; } = null!;
|
||||
[MaxLength(4096)] public string? Description { get; set; }
|
||||
public int Order { get; set; } = 0;
|
||||
public bool IsRequired { get; set; }
|
||||
|
||||
|
||||
public Guid PollId { get; set; }
|
||||
[JsonIgnore] public Poll Poll { get; set; } = null!;
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public class PollQuestion : ModelBase
|
||||
public class PollOption
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
[Required] [MaxLength(1024)] public string Label { get; set; } = null!;
|
||||
[Required][MaxLength(1024)] public string Label { get; set; } = null!;
|
||||
[MaxLength(4096)] public string? Description { get; set; }
|
||||
public int Order { get; set; } = 0;
|
||||
}
|
||||
@@ -57,8 +57,8 @@ public class PollAnswer : ModelBase
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
[Column(TypeName = "jsonb")] public Dictionary<string, JsonElement> Answer { get; set; } = null!;
|
||||
|
||||
|
||||
public Guid AccountId { get; set; }
|
||||
public Guid PollId { get; set; }
|
||||
[JsonIgnore] public Poll Poll { get; set; } = null!;
|
||||
}
|
||||
[JsonIgnore] public Poll? Poll { get; set; }
|
||||
}
|
||||
|
@@ -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));
|
||||
|
Reference in New Issue
Block a user