about summary refs log tree commit diff
path: root/Utilities/LibMatrix.HomeserverEmulator/Services/RoomStore.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-02-03 19:06:08 +0100
committerRory& <root@rory.gay>2025-02-03 19:06:08 +0100
commit040c244d35ff42b59993c85a5110d4e7aedc0237 (patch)
treed3d42436cc40a2f09b8dec87624ef45ea9acd2d7 /Utilities/LibMatrix.HomeserverEmulator/Services/RoomStore.cs
parentThe rest of warning cleanup so far. (diff)
downloadLibMatrix-040c244d35ff42b59993c85a5110d4e7aedc0237.tar.xz
Some code cleanup
Diffstat (limited to 'Utilities/LibMatrix.HomeserverEmulator/Services/RoomStore.cs')
-rw-r--r--Utilities/LibMatrix.HomeserverEmulator/Services/RoomStore.cs28
1 files changed, 5 insertions, 23 deletions
diff --git a/Utilities/LibMatrix.HomeserverEmulator/Services/RoomStore.cs b/Utilities/LibMatrix.HomeserverEmulator/Services/RoomStore.cs

index 8b35b3a..2f5fa32 100644 --- a/Utilities/LibMatrix.HomeserverEmulator/Services/RoomStore.cs +++ b/Utilities/LibMatrix.HomeserverEmulator/Services/RoomStore.cs
@@ -7,7 +7,6 @@ using System.Text.Json.Nodes; using ArcaneLibs; using ArcaneLibs.Collections; using ArcaneLibs.Extensions; -using LibMatrix.EventTypes.Spec.State; using LibMatrix.EventTypes.Spec.State.RoomInfo; using LibMatrix.HomeserverEmulator.Controllers.Rooms; using LibMatrix.Responses; @@ -19,7 +18,7 @@ public class RoomStore { public ConcurrentBag<Room> _rooms = new(); private FrozenDictionary<string, Room> _roomsById = FrozenDictionary<string, Room>.Empty; - public RoomStore(ILogger<RoomStore> logger, HSEConfiguration config) { + public RoomStore(ILogger<RoomStore> logger, HseConfiguration config) { _logger = logger; if (config.StoreData) { var path = Path.Combine(config.DataStoragePath, "rooms"); @@ -34,26 +33,9 @@ public class RoomStore { RebuildIndexes(); } - - private SemaphoreSlim a = new(1, 1); + private void RebuildIndexes() { - // a.Wait(); - // lock (_roomsById) - // _roomsById = new ConcurrentDictionary<string, Room>(_rooms.ToDictionary(u => u.RoomId)); - // foreach (var room in _rooms) { - // _roomsById.AddOrUpdate(room.RoomId, room, (key, old) => room); - // } - // - // var roomsArr = _rooms.ToArray(); - // foreach (var (id, room) in _roomsById) { - // if (!roomsArr.Any(x => x.RoomId == id)) - // _roomsById.TryRemove(id, out _); - // } - - // _roomsById = new ConcurrentDictionary<string, Room>(_rooms.ToDictionary(u => u.RoomId)); _roomsById = _rooms.ToFrozenDictionary(u => u.RoomId); - - // a.Release(); } public Room? GetRoomById(string roomId, bool createIfNotExists = false) { @@ -64,14 +46,14 @@ public class RoomStore { if (!createIfNotExists) return null; - return CreateRoom(new() { }); + return CreateRoom(new()); } public Room CreateRoom(CreateRoomRequest request, UserStore.User? user = null) { var room = new Room(roomId: $"!{Guid.NewGuid().ToString()}"); var newCreateEvent = new StateEvent() { Type = RoomCreateEventContent.EventId, - RawContent = new() { } + RawContent = new() }; foreach (var (key, value) in request.CreationContent) { @@ -246,7 +228,7 @@ public class RoomStore { Task.Run(async () => { await saveSemaphore.WaitAsync(); try { - var path = Path.Combine(HSEConfiguration.Current.DataStoragePath, "rooms", $"{RoomId}.json"); + var path = Path.Combine(HseConfiguration.Current.DataStoragePath, "rooms", $"{RoomId}.json"); Console.WriteLine($"Saving room {RoomId} to {path}!"); await File.WriteAllTextAsync(path, this.ToJson(ignoreNull: true)); }