mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-25 23:18:44 -07:00
fix: sub-room id sequence, restore sync, presence index TTL, permission races
From the local CodeRabbit review: - Scene ids: the repair and room clone assigned max + 1, which never advanced the Postgres identity sequence (live: sequence 3412, max id 3466), so the next add / clone sub-room would collide on the primary key. The repair now moves the sequence past the highest id at startup, and both let the database assign ids. - Room-level restores (datahistory/restore and the admin restore) now also restore the entry sub-room, whose blob room details serve first. - TouchRoom refreshes the room's presence index too, so players kept alive only by heartbeats no longer drop out of the instance browser after 20 min. - Sub-room permission saves match cells exactly (as the unique index does) and retry when a concurrent editor inserted the same new cell.
This commit is contained in:
@@ -118,6 +118,35 @@ public sealed class SubRoomsAndInstances2023Tests : IClassFixture<DorkNetServerF
|
||||
Assert.Equal((0, 0), await service.RepairRoomScenesAsync());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Room_level_restore_also_restores_the_entry_sub_room()
|
||||
{
|
||||
var owner = await PlayerAsync();
|
||||
var roomId = await SeedRoomAsync(owner.PlayerId, accessibility: 0, scenes: new[] { "Home", "Back" });
|
||||
await using (var scope = _factory.Services.CreateAsyncScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<DorkNetDbContext>();
|
||||
await db.RoomScenes.Where(s => s.RoomId == roomId)
|
||||
.ExecuteUpdateAsync(s => s.SetProperty(x => x.DataBlobName, "blob-old"));
|
||||
db.RoomDataBlobs.Add(new RoomDataBlobEntity { RoomId = roomId, BlobName = "blob-new", UploadedByPlayerId = owner.PlayerId });
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
using var api = Client("api", owner);
|
||||
using var response = await api.PostAsync("/api/rooms/v1/restore", new FormUrlEncodedContent(new Dictionary<string, string>
|
||||
{
|
||||
["roomId"] = roomId.ToString(), ["blobName"] = "blob-new",
|
||||
}));
|
||||
Assert.True(response.IsSuccessStatusCode, await response.Content.ReadAsStringAsync());
|
||||
|
||||
await using var check = _factory.Services.CreateAsyncScope();
|
||||
var checkDb = check.ServiceProvider.GetRequiredService<DorkNetDbContext>();
|
||||
var blobs = await checkDb.RoomScenes.AsNoTracking().Where(s => s.RoomId == roomId)
|
||||
.OrderBy(s => s.OrderIndex).Select(s => s.DataBlobName).ToListAsync();
|
||||
// The entry sub-room follows the restore; other sub-rooms keep theirs.
|
||||
Assert.Equal(new[] { "blob-new", "blob-old" }, blobs);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Startup_repair_restores_a_missing_entry_sub_room_next_to_others()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user