Fix memory leak in GameServer (#731)

* Convert entities to serializable after aggregating rather before

* Cache instances of CustomXmlSerializer and create readonly constants for reused settings

* Change CustomXmlSerializer and serializer cache to work with deserializer
This commit is contained in:
Josh 2023-04-02 18:45:19 -05:00 committed by GitHub
parent 0253864f5e
commit 2210541894
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 125 additions and 147 deletions

View file

@ -37,9 +37,8 @@ public class CollectionController : ControllerBase
GameTokenEntity token = this.GetToken();
List<SlotBase> slots = await this.database.Slots.Where(s => targetPlaylist.SlotIds.Contains(s.SlotId))
.Select(s => SlotBase.CreateFromEntity(s, token))
.ToListAsync();
List<SlotBase> slots = (await this.database.Slots.Where(s => targetPlaylist.SlotIds.Contains(s.SlotId)).ToListAsync())
.ToSerializableList(s => SlotBase.CreateFromEntity(s, token));
int total = targetPlaylist.SlotIds.Length;
@ -101,9 +100,8 @@ public class CollectionController : ControllerBase
private async Task<PlaylistResponse> GetUserPlaylists(int userId)
{
List<GamePlaylist> playlists = await this.database.Playlists.Where(p => p.CreatorId == userId)
.Select(p => GamePlaylist.CreateFromEntity(p))
.ToListAsync();
List<GamePlaylist> playlists = (await this.database.Playlists.Where(p => p.CreatorId == userId)
.ToListAsync()).ToSerializableList(GamePlaylist.CreateFromEntity);
int total = this.database.Playlists.Count(p => p.CreatorId == userId);
return new PlaylistResponse
@ -189,16 +187,16 @@ public class CollectionController : ControllerBase
if (category is CategoryWithUser categoryWithUser)
{
slots = categoryWithUser.GetSlots(this.database, user, pageStart, pageSize)
.Select(s => SlotBase.CreateFromEntity(s, token))
.ToList();
slots = (await categoryWithUser.GetSlots(this.database, user, pageStart, pageSize)
.ToListAsync())
.ToSerializableList(s => SlotBase.CreateFromEntity(s, token));
totalSlots = categoryWithUser.GetTotalSlots(this.database, user);
}
else
{
slots = category.GetSlots(this.database, pageStart, pageSize)
.Select(s => SlotBase.CreateFromEntity(s, token))
.ToList();
.ToList()
.ToSerializableList(s => SlotBase.CreateFromEntity(s, token));
totalSlots = category.GetTotalSlots(this.database);
}