Skip to content

Commit

Permalink
Fix incorrect SequentialIdStorage migration behavior (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvyden authored Aug 3, 2024
2 parents ac36f57 + 72bd398 commit eb9ea72
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
10 changes: 9 additions & 1 deletion Refresh.GameServer/Database/GameDatabaseContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,21 @@ private int GetOrCreateSequentialId<T>() where T : IRealmObject, ISequentialId
storage.SequentialId += 1;
return storage.SequentialId;
}

int objectCount = this._realm.All<T>().Count();

storage = new SequentialIdStorage
{
TypeName = name,
SequentialId = this._realm.All<T>().Count() * 2, // skip over a bunch of ids incase table is broken
};

if (objectCount != 0)
storage.SequentialId = this._realm.All<T>()
.AsEnumerable() // because realm.
.Max(t => t.SequentialId) + 1;
else
storage.SequentialId = 0;

// no need to do write block, this should only be called in a write transaction
this.SequentialIdStorage.Add(storage);

Expand Down
2 changes: 1 addition & 1 deletion Refresh.GameServer/Database/ISequentialId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ namespace Refresh.GameServer.Database;

public interface ISequentialId
{
int SequentialId { set; }
int SequentialId { get; set; }
}
1 change: 1 addition & 0 deletions Refresh.GameServer/Types/Levels/GameLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public GameSkillReward[] SkillRewards

public int SequentialId
{
get => this.LevelId;
set => this.LevelId = value;
}

Expand Down
1 change: 1 addition & 0 deletions Refresh.GameServer/Types/Photos/GamePhoto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ private void ClearSubjects()

[JsonIgnore] public int SequentialId
{
get => this.PhotoId;
set => this.PhotoId = value;
}
}
1 change: 1 addition & 0 deletions Refresh.GameServer/Types/Reviews/GameReview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public partial class GameReview : IRealmObject, ISequentialId

public int SequentialId
{
get => this.ReviewId;
set => this.ReviewId = value;
}
}

0 comments on commit eb9ea72

Please sign in to comment.