Skip to content

Commit

Permalink
Remove level playlist relations when level is deleted (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvyden authored Sep 23, 2024
2 parents f3b91ba + 4453c34 commit 2dba056
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions Refresh.GameServer/Database/GameDatabaseContext.Levels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public void DeleteLevel(GameLevel level)
this.UniquePlayLevelRelations.RemoveRange(r => r.Level == level);
this.TagLevelRelations.RemoveRange(r => r.Level == level);
this.GameReviews.RemoveRange(r => r.Level == level);
this.LevelPlaylistRelations.RemoveRange(r => r.Level == level);

IQueryable<GameSubmittedScore> scores = this.GameSubmittedScores.Where(r => r.Level == level);

Expand Down
36 changes: 20 additions & 16 deletions Refresh.GameServer/Database/GameDatabaseProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected GameDatabaseProvider(IDateTimeProvider time)
this._time = time;
}

protected override ulong SchemaVersion => 159;
protected override ulong SchemaVersion => 160;

protected override string Filename => "refreshGameServer.realm";

Expand Down Expand Up @@ -666,28 +666,32 @@ protected override void Migrate(Migration migration, ulong oldVersion)
// IQueryable<GamePlaylist>? newGamePlaylists = migration.NewRealm.All<GamePlaylist>();

// if (oldVersion < 155)
// for (int i = 0; i < newGamePlaylists.Count(); i++)
// {
// dynamic oldGamePlaylist = oldGamePlaylists.ElementAt(i);
// GamePlaylist newGamePlaylist = newGamePlaylists.ElementAt(i);
// }
// for (int i = 0; i < newGamePlaylists.Count(); i++)
// {
// dynamic oldGamePlaylist = oldGamePlaylists.ElementAt(i);
// GamePlaylist newGamePlaylist = newGamePlaylists.ElementAt(i);
// }

// We weren't deleting level playlist relations when a level was deleted. Version 160 fixes this.
if (oldVersion < 160)
migration.NewRealm.RemoveRange(migration.NewRealm.All<LevelPlaylistRelation>().Where(r => r.Level == null));

// IQueryable<dynamic>? oldLevelPlaylistRelations = migration.OldRealm.DynamicApi.All("LevelPlaylistRelation");
// IQueryable<LevelPlaylistRelation>? newLevelPlaylistRelations = migration.NewRealm.All<LevelPlaylistRelation>();
// if (oldVersion < 155)
// for (int i = 0; i < newGamePlaylists.Count(); i++)
// {
// dynamic oldLevelPlaylistRelation = oldLevelPlaylistRelations.ElementAt(i);
// LevelPlaylistRelation newLevelPlaylistRelation = newLevelPlaylistRelations.ElementAt(i);
// }
// for (int i = 0; i < newLevelPlaylistRelations.Count(); i++)
// {
// dynamic oldLevelPlaylistRelation = oldLevelPlaylistRelations.ElementAt(i);
// LevelPlaylistRelation newLevelPlaylistRelation = newLevelPlaylistRelations.ElementAt(i);
// }

// IQueryable<dynamic>? oldSubPlaylistRelations = migration.OldRealm.DynamicApi.All("SubPlaylistRelation");
// IQueryable<SubPlaylistRelation>? newSubPlaylistRelations = migration.NewRealm.All<SubPlaylistRelation>();
// if (oldVersion < 155)
// for (int i = 0; i < newGamePlaylists.Count(); i++)
// {
// dynamic oldSubPlaylistRelation = oldSubPlaylistRelations.ElementAt(i);
// SubPlaylistRelation newSubPlaylistRelation = newSubPlaylistRelations.ElementAt(i);
// }
// for (int i = 0; i < newSubPlaylistRelations.Count(); i++)
// {
// dynamic oldSubPlaylistRelation = oldSubPlaylistRelations.ElementAt(i);
// SubPlaylistRelation newSubPlaylistRelation = newSubPlaylistRelations.ElementAt(i);
// }
}
}
2 changes: 2 additions & 0 deletions Refresh.GameServer/Types/Playlists/LevelPlaylistRelation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace Refresh.GameServer.Types.Playlists;

#nullable disable

/// <summary>
/// A mapping of playlist -> sub-level
/// </summary>
Expand Down

0 comments on commit 2dba056

Please sign in to comment.