Parallel data getting

This commit is contained in:
BOT Alex 2023-07-02 21:39:49 +02:00
parent 059088121e
commit 81c9030daf
11 changed files with 808 additions and 8 deletions

View file

@ -5,12 +5,14 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
<EnableSdkContainerSupport>true</EnableSdkContainerSupport>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.19" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.19" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Build.Containers" Version="7.0.305" />
<PackageReference Include="MudBlazor" Version="6.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

View file

@ -17,7 +17,6 @@
<MudButton Variant="Variant.Filled" OnClick=StartLearning Color="Color.Primary">Start learning!</MudButton>
</MudContainer>
<MudContainer Class="justify-center d-flex">
@if (Charecters != null)
{
@ -98,19 +97,28 @@
StateHasChanged();
}
async void LoadAllChunksIntoLocalStorage()
async Task LoadAllChunksIntoLocalStorage()
{
isLoading = true;
for (int i = 0; i < numOfChunks; i++)
string[] jsonChunks = new string[numOfChunks];
Parallel.For(0, numOfChunks, async (i)=>
{
string? jsonChunk = await httpClient.GetStringAsync($"Data/Normalized_chunk_{i.ToString("000")}.json");
await Task.Delay(10*i);
jsonChunks[i] = await httpClient.GetStringAsync($"Data/Normalized_chunk_{i.ToString("000")}.json");
if (string.IsNullOrEmpty(jsonChunk)) continue;
if (string.IsNullOrEmpty(jsonChunks[i])) return;
await localStorage.SetItemAsync($"Normalized_chunk_{i.ToString("000")}.json", jsonChunk);
await localStorage.SetItemAsync($"Normalized_chunk_{i.ToString("000")}.json", jsonChunks[i]);
savedChunks = i + 1;
});
while (jsonChunks.Any(x => x == null))
{
await Task.Delay(1);
StateHasChanged();
}
isLoading = false;
isSavedLocally = true;
StateHasChanged();

View file

@ -8,7 +8,7 @@
},
"dotnetRunMessages": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "http://localhost:5198;http://0.0.0.0:420/"
"applicationUrl": "http://localhost:5198;https://0.0.0.0:420/"
},
"IIS Express": {
"commandName": "IISExpress",

View file

@ -12,7 +12,6 @@
<link href="manifest.json" rel="manifest" />
<link rel="apple-touch-icon" sizes="512x512" href="icon-512.png" />
<link rel="apple-touch-icon" sizes="192x192" href="icon-192.png" />
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
</head>