diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-05-27 02:23:30 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-05-27 02:23:30 +0200 |
commit | ac7ed016b00941380099d9a0b2601f4bc353f39f (patch) | |
tree | a0f9fc1baee763a528aef2cd04a920815ef3906d /MatrixRoomUtils.Web/Pages | |
parent | Been a while since I last committed (diff) | |
download | MatrixUtils-ac7ed016b00941380099d9a0b2601f4bc353f39f.tar.xz |
Remove a bunch of caching, make room listings more reliable
Diffstat (limited to 'MatrixRoomUtils.Web/Pages')
8 files changed, 36 insertions, 34 deletions
diff --git a/MatrixRoomUtils.Web/Pages/DataExportPage.razor b/MatrixRoomUtils.Web/Pages/DataExportPage.razor index 58e4111..49fb700 100644 --- a/MatrixRoomUtils.Web/Pages/DataExportPage.razor +++ b/MatrixRoomUtils.Web/Pages/DataExportPage.razor @@ -59,7 +59,7 @@ else var resolvedHomeserver = (await new RemoteHomeServer(hs).Configure()).FullHomeServerDomain; RuntimeCache.HomeserverResolutionCache.Add(hs, new() { Result = resolvedHomeserver, ResolutionTime = DateTime.Now }); - await LocalStorageWrapper.SaveToLocalStorage(LocalStorage); + await LocalStorageWrapper.SaveCacheToLocalStorage(LocalStorage); Console.WriteLine("Saved to local storage:"); Console.WriteLine(JsonSerializer.Serialize(RuntimeCache.HomeserverResolutionCache, new JsonSerializerOptions() diff --git a/MatrixRoomUtils.Web/Pages/DevOptions.razor b/MatrixRoomUtils.Web/Pages/DevOptions.razor index 9ade1b8..c2894b3 100644 --- a/MatrixRoomUtils.Web/Pages/DevOptions.razor +++ b/MatrixRoomUtils.Web/Pages/DevOptions.razor @@ -39,7 +39,6 @@ { await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); await base.OnInitializedAsync(); - await LocalStorageWrapper.SaveToLocalStorage(LocalStorage); Task.Run(async () => { while (true) @@ -62,7 +61,7 @@ { RuntimeCache.GenericResponseCache.Clear(); RuntimeCache.HomeserverResolutionCache.Clear(); - await LocalStorageWrapper.SaveToLocalStorage(LocalStorage); + await LocalStorageWrapper.SaveCacheToLocalStorage(LocalStorage); } protected async Task RandomiseCacheTimers() @@ -75,7 +74,7 @@ cacheItem.Value.ExpiryTime = DateTime.Now.AddSeconds(Random.Shared.Next(15, 120)); } - await LocalStorageWrapper.SaveToLocalStorage(LocalStorage); + await LocalStorageWrapper.SaveCacheToLocalStorage(LocalStorage); } } diff --git a/MatrixRoomUtils.Web/Pages/Index.razor b/MatrixRoomUtils.Web/Pages/Index.razor index 8be8570..decdb0c 100644 --- a/MatrixRoomUtils.Web/Pages/Index.razor +++ b/MatrixRoomUtils.Web/Pages/Index.razor @@ -28,6 +28,5 @@ Small collection of tools to do not-so-everyday things. await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); } await base.OnInitializedAsync(); - await LocalStorageWrapper.ReloadLocalStorage(LocalStorage); } } \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Pages/MediaLocator.razor b/MatrixRoomUtils.Web/Pages/MediaLocator.razor index 06256f0..19a0d4e 100644 --- a/MatrixRoomUtils.Web/Pages/MediaLocator.razor +++ b/MatrixRoomUtils.Web/Pages/MediaLocator.razor @@ -113,7 +113,7 @@ homeservers.Add(await rhs.ResolveHomeserverFromWellKnown(line)); StateHasChanged(); if(Random.Shared.Next(0,101) == 50) - await LocalStorageWrapper.SaveToLocalStorage(LocalStorage); + await LocalStorageWrapper.SaveCacheToLocalStorage(LocalStorage); } catch (Exception e) { diff --git a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor index 08cdc2c..4b9c2f6 100644 --- a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor +++ b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor @@ -33,13 +33,13 @@ else </tr> </thead> <tbody> - @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.server" && x.content.Entity != null)) + @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.server" && x.Content.Entity != null)) { <tr> - <td>Entity: @policyEvent.content.Entity<br/>State: @policyEvent.StateKey</td> - <td>@policyEvent.content.Reason</td> + <td>Entity: @policyEvent.Content.Entity<br/>State: @policyEvent.StateKey</td> + <td>@policyEvent.Content.Reason</td> <td> - @policyEvent.content.ExpiryDateTime + @policyEvent.Content.ExpiryDateTime </td> <td> <button class="btn" @* @onclick="async () => await RemovePolicyAsync(policyEvent)" *@>Edit</button> @@ -59,11 +59,11 @@ else </tr> </thead> <tbody> - @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.server" && x.content.Entity == null)) + @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.server" && x.Content.Entity == null)) { <tr> <td>@policyEvent.StateKey</td> - <td>@policyEvent.content.ToJson(indent: false, ignoreNull: true)</td> + <td>@policyEvent.Content.ToJson(indent: false, ignoreNull: true)</td> </tr> } </tbody> @@ -88,13 +88,13 @@ else </tr> </thead> <tbody> - @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && x.content.Entity != null)) + @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && x.Content.Entity != null)) { <tr> - <td>Entity: @policyEvent.content.Entity<br/>State: @policyEvent.StateKey</td> - <td>@policyEvent.content.Reason</td> + <td>Entity: @policyEvent.Content.Entity<br/>State: @policyEvent.StateKey</td> + <td>@policyEvent.Content.Reason</td> <td> - @policyEvent.content.ExpiryDateTime + @policyEvent.Content.ExpiryDateTime </td> <td> <button class="btn btn-danger" @* @onclick="async () => await RemovePolicyAsync(policyEvent)" *@>Remove</button> @@ -113,11 +113,11 @@ else </tr> </thead> <tbody> - @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && x.content.Entity == null)) + @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && x.Content.Entity == null)) { <tr> <td>@policyEvent.StateKey</td> - <td>@policyEvent.content.ToJson(indent: false, ignoreNull: true)</td> + <td>@policyEvent.Content.ToJson(indent: false, ignoreNull: true)</td> </tr> } </tbody> @@ -146,17 +146,17 @@ else </tr> </thead> <tbody> - @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && x.content.Entity != null)) + @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && x.Content.Entity != null)) { <tr> @if (_enableAvatars) { - <td scope="col"><img style="width: 48px; height: 48px; aspect-ratio: unset; border-radius: 50%;" src="@(avatars.ContainsKey(policyEvent.content.Entity) ? avatars[policyEvent.content.Entity] : "")"/></td> + <td scope="col"><img style="width: 48px; height: 48px; aspect-ratio: unset; border-radius: 50%;" src="@(avatars.ContainsKey(policyEvent.Content.Entity) ? avatars[policyEvent.Content.Entity] : "")"/></td> } - <td style="word-wrap: anywhere;">Entity: @string.Join("", policyEvent.content.Entity.Take(64))<br/>State: @string.Join("", policyEvent.StateKey.Take(64))</td> - <td>@policyEvent.content.Reason</td> + <td style="word-wrap: anywhere;">Entity: @string.Join("", policyEvent.Content.Entity.Take(64))<br/>State: @string.Join("", policyEvent.StateKey.Take(64))</td> + <td>@policyEvent.Content.Reason</td> <td> - @policyEvent.content.ExpiryDateTime + @policyEvent.Content.ExpiryDateTime </td> <td> <button class="btn btn-danger" @* @onclick="async () => await RemovePolicyAsync(policyEvent)" *@>Remove</button> @@ -175,11 +175,11 @@ else </tr> </thead> <tbody> - @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && x.content.Entity == null)) + @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && x.Content.Entity == null)) { <tr> <td>@policyEvent.StateKey</td> - <td>@policyEvent.content.ToJson(indent: false, ignoreNull: true)</td> + <td>@policyEvent.Content.ToJson(indent: false, ignoreNull: true)</td> </tr> } </tbody> @@ -261,9 +261,9 @@ else private async Task GetAllAvatars() { - foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && x.content.Entity != null)) + foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.user" && x.Content.Entity != null)) { - await GetAvatar(policyEvent.content.Entity); + await GetAvatar(policyEvent.Content.Entity); } StateHasChanged(); } diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor index 35bf501..a8b8fd4 100644 --- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor +++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManager.razor @@ -20,7 +20,7 @@ else @foreach (var room in Spaces) { <a style="color: unset; text-decoration: unset;" href="/RoomManager/Space/@room.RoomId.Replace('.', '~')"> - <RoomListItem Room="@room" ShowOwnProfile="true"></RoomListItem> + <RoomListItem Room="@room" ShowOwnProfile="false"></RoomListItem> </a> } </details> @@ -44,19 +44,23 @@ else protected override async Task OnInitializedAsync() { + Console.WriteLine("Initializing room manager"); await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); + Console.WriteLine("Loaded from local storage"); await base.OnInitializedAsync(); + Console.WriteLine("Initialized base"); if (RuntimeCache.CurrentHomeServer == null) { NavigationManager.NavigateTo("/Login"); return; } - Rooms = await RuntimeCache.CurrentHomeServer.GetJoinedRooms(); + Console.WriteLine("Fetching joined rooms"); + var _rooms = await RuntimeCache.CurrentHomeServer.GetJoinedRooms(); StateHasChanged(); - Console.WriteLine($"Got {Rooms.Count} rooms"); + Console.WriteLine($"Got {_rooms.Count} rooms"); var semaphore = new SemaphoreSlim(10); var tasks = new List<Task<Room?>>(); - foreach (var room in Rooms) + foreach (var room in _rooms) { tasks.Add(CheckIfSpace(room, semaphore)); } @@ -81,7 +85,6 @@ else { Console.WriteLine($"Room {room.RoomId} is a space!"); Spaces.Add(room); - Rooms.Remove(room); StateHasChanged(); return room; } @@ -92,6 +95,7 @@ else } else { + Rooms.Add(room); //this is fine, apprently... // Console.WriteLine($"Room {room.RoomId} has no Content.type in m.room.create!"); } diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerCreateRoom.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerCreateRoom.razor index 7b4db37..8cbbca6 100644 --- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerCreateRoom.razor +++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerCreateRoom.razor @@ -79,7 +79,7 @@ <details> @code{ - private static string[] ImplementedStates = new[] { "m.room.avatar", "m.room.history_visibility", "m.room.guest_access", }; + private static readonly string[] ImplementedStates = { "m.room.avatar", "m.room.history_visibility", "m.room.guest_access", }; } <summary>@creationEvent.InitialState.Count(x => !ImplementedStates.Contains(x.Type)) custom states</summary> diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor index a44b2b4..e9d1421 100644 --- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor +++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor @@ -16,7 +16,7 @@ @foreach (var stateEvent in States.OrderBy(x => x.StateKey).ThenBy(x => x.Type)) { <p>@stateEvent.StateKey/@stateEvent.Type:</p> - <pre>@stateEvent.content.ToJson()</pre> + <pre>@stateEvent.Content.ToJson()</pre> } </details> |