blob: 0843d5f8b850eaa37f62f4cc2fd33c2b0a743f60 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
@page "/DevOptions"
@using MatrixRoomUtils.Core.Extensions
@inject NavigationManager NavigationManager
@inject ILocalStorageService LocalStorage
<PageTitle>Developer options</PageTitle>
<h3>Rory&::MatrixUtils - Developer options</h3>
<hr/>
<InputCheckbox @bind-Value="@LocalStorageWrapper.Settings.DeveloperSettings.EnableLogViewers" @oninput="@LogStuff"></InputCheckbox><label> Enable log views</label><br/>
<InputCheckbox @bind-Value="@LocalStorageWrapper.Settings.DeveloperSettings.EnableConsoleLogging" @oninput="@LogStuff"></InputCheckbox><label> Enable console logging</label><br/>
<InputCheckbox @bind-Value="@LocalStorageWrapper.Settings.DeveloperSettings.EnablePortableDevtools" @oninput="@LogStuff"></InputCheckbox><label> Enable portable devtools</label><br/>
<button @onclick="@DropCaches">Drop caches</button>
<button @onclick="@RandomiseCacheTimers">Randomise cache timers</button>
<br/>
<details open>
<summary>View caches</summary>
<p>Generic cache:</p>
<ul>
@foreach (var item in RuntimeCache.GenericResponseCache) {
<li>
@item.Key: @item.Value.Cache.Count entries<br/>
@if (item.Value.Cache.Count > 0) {
<p>Earliest expiry: @(item.Value.Cache.Min(x => x.Value.ExpiryTime)) (@string.Format("{0:g}", item.Value.Cache.Min(x => x.Value.ExpiryTime).Value.Subtract(DateTime.Now)) from now)</p>
@* <p>Average expiry: @(item.Value.Cache.Average(x => x.Value.ExpiryTime.Value))(@item.Value.Cache.Average(x => x.Value.ExpiryTime).Value.Subtract(DateTime.Now) from now)</p> *@
<p>Last expiry: @(item.Value.Cache.Max(x => x.Value.ExpiryTime)) (@string.Format("{0:g}", item.Value.Cache.Max(x => x.Value.ExpiryTime).Value.Subtract(DateTime.Now)) from now)</p>
}
</li>
}
</ul>
</details>
@code {
protected override async Task OnInitializedAsync() {
await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
await base.OnInitializedAsync();
Task.Run(async () => {
while (true) {
await Task.Delay(1000);
StateHasChanged();
}
});
}
protected async Task LogStuff() {
await Task.Delay(100);
Console.WriteLine($"Settings: {LocalStorageWrapper.Settings.ToJson()}");
await LocalStorageWrapper.SaveToLocalStorage(LocalStorage);
}
protected async Task DropCaches() {
foreach (var (key, value) in RuntimeCache.GenericResponseCache) {
value.Cache.Clear();
}
//RuntimeCache.GenericResponseCache.Clear();
RuntimeCache.HomeserverResolutionCache.Clear();
await LocalStorageWrapper.SaveCacheToLocalStorage(LocalStorage);
}
protected async Task RandomiseCacheTimers() {
foreach (var keyValuePair in RuntimeCache.GenericResponseCache) {
Console.WriteLine($"Randomising cache timer for {keyValuePair.Key}");
foreach (var cacheItem in keyValuePair.Value.Cache) {
cacheItem.Value.ExpiryTime = DateTime.Now.AddSeconds(Random.Shared.Next(15, 120));
}
await LocalStorageWrapper.SaveCacheToLocalStorage(LocalStorage);
}
}
}
|