From 040c244d35ff42b59993c85a5110d4e7aedc0237 Mon Sep 17 00:00:00 2001 From: Rory& Date: Mon, 3 Feb 2025 19:06:08 +0100 Subject: Some code cleanup --- .../Services/RoomStore.cs | 28 ++++------------------ 1 file changed, 5 insertions(+), 23 deletions(-) (limited to 'Utilities/LibMatrix.HomeserverEmulator/Services/RoomStore.cs') 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 _rooms = new(); private FrozenDictionary _roomsById = FrozenDictionary.Empty; - public RoomStore(ILogger logger, HSEConfiguration config) { + public RoomStore(ILogger 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(_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(_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)); } -- cgit 1.5.1