Manually fetch slot types instead of relying on foreign key being loaded

This commit is contained in:
Slendy 2024-05-13 21:53:52 -05:00
commit cd0c85308a
No known key found for this signature in database
GPG key ID: 7288D68361B91428
2 changed files with 20 additions and 10 deletions

View file

@ -132,7 +132,6 @@ public class ScoreController : ControllerBase
await this.database.SaveChangesAsync();
ScoreEntity? existingScore = await this.database.Scores
.Include(s => s.Slot)
.Where(s => s.SlotId == slot.SlotId)
.Where(s => s.ChildSlotId == 0 || s.ChildSlotId == childId)
.Where(s => s.UserId == token.UserId)

View file

@ -35,7 +35,9 @@ public class ActivityEntityEventHandler : IEntityEventHandler
},
CommentEntity comment => comment.Type switch
{
CommentType.Level => comment.TargetSlot?.Type switch
CommentType.Level => database.Slots.Where(s => s.SlotId == comment.TargetSlotId)
.Select(s => s.Type)
.FirstOrDefault() switch
{
SlotType.User => new LevelCommentActivityEntity
{
@ -55,9 +57,9 @@ public class ActivityEntityEventHandler : IEntityEventHandler
},
_ => null,
},
PhotoEntity photo => photo.SlotId switch
{
_ => photo.Slot?.Type switch
PhotoEntity photo => database.Slots.Where(s => s.SlotId == photo.SlotId)
.Select(s => s.Type)
.FirstOrDefault() switch
{
SlotType.User => new LevelPhotoActivity
{
@ -69,8 +71,9 @@ public class ActivityEntityEventHandler : IEntityEventHandler
// All other photos (story, moon, pod, etc.)
_ => null,
},
},
ScoreEntity score => score.Slot.Type switch
ScoreEntity score => database.Slots.Where(s => s.SlotId == score.SlotId)
.Select(s => s.Type)
.FirstOrDefault() switch
{
// Don't add story scores or versus scores
SlotType.User when score.Type != 7 => new ScoreActivityEntity
@ -82,7 +85,9 @@ public class ActivityEntityEventHandler : IEntityEventHandler
},
_ => null,
},
HeartedLevelEntity heartedLevel => heartedLevel.Slot.Type switch
HeartedLevelEntity heartedLevel => database.Slots.Where(s => s.SlotId == heartedLevel.SlotId)
.Select(s => s.Type)
.FirstOrDefault() switch
{
SlotType.User => new LevelActivityEntity
{
@ -226,7 +231,11 @@ public class ActivityEntityEventHandler : IEntityEventHandler
// don't track versus levels
if (oldScore.Type == 7) break;
if (score.Slot.Type != SlotType.User) break;
SlotType slotType = database.Slots.Where(s => s.SlotId == score.SlotId)
.Select(s => s.Type)
.FirstOrDefault();
if (slotType != SlotType.User) break;
if (oldScore.Points > score.Points) break;
@ -349,7 +358,9 @@ public class ActivityEntityEventHandler : IEntityEventHandler
{
ActivityEntity? activity = entity switch
{
HeartedLevelEntity heartedLevel => heartedLevel.Slot.Type switch
HeartedLevelEntity heartedLevel => database.Slots.Where(s => s.SlotId == heartedLevel.SlotId)
.Select(s => s.Type)
.FirstOrDefault() switch
{
SlotType.User => new LevelActivityEntity
{