Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect SequentialIdStorage migration behavior #608

Merged
merged 2 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading