Skip to content

Commit f5bdf00

Browse files
committed
Turns out you can Include() lists of related entities
1 parent 0aa4865 commit f5bdf00

6 files changed

Lines changed: 13 additions & 8 deletions

File tree

Refresh.Core/Extensions/PhotoExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static SerializedPhoto FromGamePhoto(GamePhoto photo, DataContext dataCon
2222
PhotoSubjects = [],
2323
};
2424

25-
foreach (GamePhotoSubject subject in dataContext.Database.GetSubjectsInPhoto(photo).ToList())
25+
foreach (GamePhotoSubject subject in photo.Subjects)
2626
{
2727
SerializedPhotoSubject newSubject = new()
2828
{

Refresh.Database/GameDatabaseContext.Photos.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public partial class GameDatabaseContext // Photos
1919
.Include(p => p.Publisher.Statistics)
2020
.Include(p => p.Level)
2121
.Include(p => p.Level!.Publisher)
22-
.Include(p => p.Level!.Publisher!.Statistics);
22+
.Include(p => p.Level!.Publisher!.Statistics)
23+
.Include(p => p.Subjects);
2324

2425
private IQueryable<GamePhotoSubject> GamePhotoSubjectsIncluded => this.GamePhotoSubjects
2526
.Include(p => p.User)
@@ -32,7 +33,8 @@ public partial class GameDatabaseContext // Photos
3233
.Include(p => p.Photo!.Level!.Publisher!.Statistics)
3334
.Include(p => p.Photo!.LargeAsset)
3435
.Include(p => p.Photo!.MediumAsset)
35-
.Include(p => p.Photo!.SmallAsset);
36+
.Include(p => p.Photo!.SmallAsset)
37+
.Include(p => p.Photo!.Subjects);
3638

3739
public GamePhoto UploadPhoto(IPhotoUpload photo, IEnumerable<IPhotoUploadSubject> subjects, GameUser publisher, GameLevel? level)
3840
{

Refresh.Database/Models/Photos/GamePhoto.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public partial class GamePhoto : ISequentialId
4343
public string PlanHash { get; set; }
4444

4545
#region Subjects
46+
/// <summary>
47+
/// A list of subjects, initialized using Include()
48+
/// </summary>
49+
public List<GamePhotoSubject> Subjects { get; set; }
4650

4751
#nullable restore
4852

Refresh.Interfaces.APIv3/Endpoints/DataTypes/Response/Users/Photos/ApiGamePhotoResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class ApiGamePhotoResponse : IApiResponse, IDataConvertableFrom<ApiGamePh
4747
LargeHash = old.LargeAsset.IsPSP ? $"psp/{old.LargeAsset.AssetHash}" : old.LargeAsset.AssetHash,
4848
PlanHash = old.PlanHash,
4949

50-
Subjects = ApiGamePhotoSubjectResponse.FromOldList(dataContext.Database.GetSubjectsInPhoto(old), dataContext),
50+
Subjects = ApiGamePhotoSubjectResponse.FromOldList(old.Subjects, dataContext),
5151
};
5252
}
5353

Refresh.Interfaces.Game/Types/Activity/SerializedEvents/SerializedEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public abstract class SerializedEvent : IDataConvertableFrom<SerializedEvent, Ev
7777
case EventType.LevelPlay:
7878
return SerializedLevelPlayEvent.FromSerializedLevelEvent(FromOldLevelEvent(old, level!));
7979
case EventType.PhotoUpload:
80-
return SerializedPhotoUploadEvent.FromSerializedLevelEvent(FromOldLevelEvent(old, level!), photo!, dataContext);
80+
return SerializedPhotoUploadEvent.FromSerializedLevelEvent(FromOldLevelEvent(old, level!), photo!);
8181
case EventType.LevelScore:
8282
return SerializedScoreSubmitEvent.FromSerializedLevelEvent(FromOldLevelEvent(old, level!), score!);
8383
case EventType.NewsPost:

Refresh.Interfaces.Game/Types/Activity/SerializedEvents/SerializedPhotoUploadEvent.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Xml.Serialization;
2-
using Refresh.Core.Types.Data;
32
using Refresh.Database.Models.Photos;
43

54
namespace Refresh.Interfaces.Game.Types.Activity.SerializedEvents;
@@ -9,7 +8,7 @@ public class SerializedPhotoUploadEvent : SerializedLevelEvent
98
[XmlElement("photo_id")] public int PhotoId { get; set; }
109
[XmlElement("user_in_photo")] public List<string> UsersInPhoto = [];
1110

12-
public static SerializedPhotoUploadEvent? FromSerializedLevelEvent(SerializedLevelEvent? e, GamePhoto? photo, DataContext dataContext)
11+
public static SerializedPhotoUploadEvent? FromSerializedLevelEvent(SerializedLevelEvent? e, GamePhoto? photo)
1312
{
1413
if (e == null || photo == null)
1514
return null;
@@ -22,7 +21,7 @@ public class SerializedPhotoUploadEvent : SerializedLevelEvent
2221
Type = e.Type,
2322

2423
PhotoId = photo.PhotoId,
25-
UsersInPhoto = dataContext.Database.GetSubjectsInPhoto(photo).Select(s => s.DisplayName).ToList(),
24+
UsersInPhoto = photo.Subjects.Select(s => s.DisplayName).ToList(),
2625
};
2726
}
2827
}

0 commit comments

Comments
 (0)