mirror of
https://github.com/rightup/pyMC_Repeater.git
synced 2026-03-28 17:43:06 +01:00
Allow bypassing cache in update check endpoint with optional force parameter
This commit is contained in:
@@ -481,12 +481,20 @@ class UpdateAPIEndpoints:
|
||||
if cherrypy.request.method not in ("POST", "GET"):
|
||||
raise cherrypy.HTTPError(405)
|
||||
|
||||
# Honour the cache to avoid hammering GitHub
|
||||
# Allow caller to bypass cache with {"force": true}
|
||||
body = {}
|
||||
try:
|
||||
body = cherrypy.request.json or {}
|
||||
except Exception:
|
||||
pass
|
||||
force = bool(body.get("force", False))
|
||||
|
||||
# Honour the cache to avoid hammering GitHub (unless forced)
|
||||
snap = _state.snapshot()
|
||||
if snap["state"] == "checking":
|
||||
return self._ok({"message": "Check already in progress", "state": "checking"})
|
||||
|
||||
if snap["last_checked"] is not None:
|
||||
if not force and snap["last_checked"] is not None:
|
||||
age = (datetime.utcnow() - _state.last_checked).total_seconds()
|
||||
if age < CHECK_CACHE_TTL and snap["latest_version"] is not None:
|
||||
return self._ok({"message": "Using cached result", "state": snap["state"], **snap})
|
||||
|
||||
Reference in New Issue
Block a user