Skip to content

Commit

Permalink
archive status spam fix
Browse files Browse the repository at this point in the history
package page will no longer spam status endpoint
  • Loading branch information
shukriadams committed Oct 23, 2024
1 parent 075c5d2 commit f6f1254
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Tetrifact.Core/ArchiveService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public async Task CreateNextQueuedArchive()

await this.CreateArchive(archiveQueueInfo.PackageId);

progress.State = PackageArchiveCreationStates.Processed_CleanupRequired;
progress.State = PackageArchiveCreationStates.Processed_ArchiveAvailable;
_cache.Set(progressCacheKey, progress);

// finally, cleanup queue file
Expand Down
3 changes: 1 addition & 2 deletions src/Tetrifact.Core/PackageArchiveCreationStates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public enum PackageArchiveCreationStates
ArchiveGenerating,
Processed_PackageNotFound,
Processed_ArchiveAvailable,
Processed_ArchiveNotGenerated,
Processed_CleanupRequired
Processed_ArchiveNotGenerated
}
}
6 changes: 5 additions & 1 deletion src/Tetrifact.Web/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,13 @@ public IActionResult ArchiveStatus(string packageId)
try
{
string progressCacheKey = _archiveService.GetArchiveProgressKey(packageId);
// try from cache first, if under active creation, this will be faster
ArchiveProgressInfo archiveGenerationStatus = _cache.Get<ArchiveProgressInfo>(progressCacheKey);
if (archiveGenerationStatus == null)
// the longer way
archiveGenerationStatus = _archiveService.GetPackageArchiveStatus(packageId);

ViewData["packageId"] = packageId;
ViewData["packageId"] = packageId;
ViewData["layoutViewModel"] = new LayoutViewModel {
PageTitle = "Archive status",
ServerName = _settings.ServerName,
Expand Down
4 changes: 2 additions & 2 deletions src/Tetrifact.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void ConfigureServices(IServiceCollection services)
});

services.AddMemoryCache();
services.AddResponseCompression();
services.AddResponseCompression(); // http compression
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
}

Expand Down Expand Up @@ -156,7 +156,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseRouting();
app.UseResponseCompression();
app.UseResponseCompression(); // http compression

IServiceProvider serviceProvider = app.ApplicationServices;
app.UseEndpoints(endpoints =>
Expand Down
6 changes: 3 additions & 3 deletions src/Tetrifact.Web/Views/Shared/ArchiveProgress.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
string packageId = ViewData["packageId"] as string;
}

<div data-complete="@(Model != null && Model.State == PackageArchiveCreationStates.Processed_ArchiveAvailable)">
<div data-complete="@(Model.State)">
@{
// TODO :simply this if statement
}
@if (Model == null || Model.State == PackageArchiveCreationStates.Processed_ArchiveNotGenerated || Model.State == PackageArchiveCreationStates.Processed_ArchiveAvailable || Model.State == PackageArchiveCreationStates.Processed_CleanupRequired)
@if (Model.State == PackageArchiveCreationStates.Processed_ArchiveNotGenerated || Model.State == PackageArchiveCreationStates.Processed_ArchiveAvailable)
{
<a class="button button-header" href="/v1/archives/@packageId">&#10515; Download</a>
}
Expand All @@ -21,7 +21,7 @@
else if (Model.State == PackageArchiveCreationStates.ArchiveGenerating)
{
<text>
Preparing package for dowload.
Preparing package for download.
</text>

@if (Model.StartedUtc.HasValue)
Expand Down
5 changes: 3 additions & 2 deletions src/Tetrifact.Web/wwwroot/scripts/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ document.addEventListener('click', onClick, false);
if (timer !== null) {
const node = document.createElement('div')
node.innerHTML = html
const isComplete = node.getAttribute('data-complete')
let status = node.children[0].getAttribute('data-complete'),
isInProgress = status == 'ArchiveGenerating' || status == 'Queued'

if (isComplete == 'true') {
if (!isInProgress) {
window.clearInterval(timer)
timer = null
}
Expand Down

0 comments on commit f6f1254

Please sign in to comment.