Skip to content

Commit

Permalink
Added response codes and configurable reindex throttle
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoboss committed Dec 5, 2023
1 parent b6c3f40 commit 7f21e2f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions TRENZ.Docs.API/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ public async Task<IndexStats> Stats()
}

[HttpGet]
public async Task Reindex([FromQuery] string? key, CancellationToken cancellationToken = default)
public async Task<IActionResult> Reindex([FromQuery] string? key, CancellationToken cancellationToken = default)
{
if (_configuration["ReindexPassword"] != key)
return;
return Unauthorized();

#if !DEBUG
if (DateTime.Now - _lastReindex < TimeSpan.FromMinutes(30))
return;
if (DateTime.Now - _lastReindex < TimeSpan.FromSeconds(_configuration.GetValue<int>("ReindexThrottling")))
return new StatusCodeResult(429);

_lastReindex = DateTime.Now;
#endif

await _indexWorker.DoReindex(cancellationToken);

return Ok();
}
}
3 changes: 2 additions & 1 deletion TRENZ.Docs.API/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"ReindexThrottling": 600
}

0 comments on commit 7f21e2f

Please sign in to comment.