Reduce API startup storage prewarm
CI / python (push) Has been cancelled
CI / rust (push) Has been cancelled

This commit is contained in:
2026-05-16 19:21:27 +03:00
parent d738f3fc39
commit c27998693e
2 changed files with 7 additions and 4 deletions
@@ -105,8 +105,11 @@ class FileStorage:
directory = self._collection_dir(collection) directory = self._collection_dir(collection)
if not directory.exists(): if not directory.exists():
return [] return []
if limit is not None and limit <= 0:
return []
documents: list[dict[str, Any]] = [] documents: list[dict[str, Any]] = []
for path in sorted(directory.glob("*.json")): paths = directory.glob("*.json") if limit is not None else sorted(directory.glob("*.json"))
for path in paths:
try: try:
documents.append(orjson.loads(path.read_bytes())) documents.append(orjson.loads(path.read_bytes()))
except (FileNotFoundError, orjson.JSONDecodeError): except (FileNotFoundError, orjson.JSONDecodeError):
+3 -3
View File
@@ -585,7 +585,7 @@ def _load_persisted_state() -> None:
_rbac.users[access.user_id] = access _rbac.users[access.user_id] = access
for payload in _storage.list_documents("privacy_markers"): for payload in _storage.list_documents("privacy_markers"):
_privacy.upsert_marker(PrivacyMarker.model_validate(payload)) _privacy.upsert_marker(PrivacyMarker.model_validate(payload))
version_load_limit = int(os.environ.get("SFERA_STARTUP_OBJECT_VERSION_LIMIT", "5000")) version_load_limit = int(os.environ.get("SFERA_STARTUP_OBJECT_VERSION_LIMIT", "0"))
for payload in _storage.list_documents("object_versions", limit=version_load_limit): for payload in _storage.list_documents("object_versions", limit=version_load_limit):
_versions.upsert_version(SemanticObjectVersion.model_validate(payload)) _versions.upsert_version(SemanticObjectVersion.model_validate(payload))
@@ -2338,10 +2338,10 @@ async def download_windows_agent_cmd_installer(request: Request, agent_id: str |
if agent_id: if agent_id:
installer_url = f"{installer_url}?agent_id={quote(agent_id, safe='')}" installer_url = f"{installer_url}?agent_id={quote(agent_id, safe='')}"
escaped_installer_url = installer_url.replace("%", "%%") escaped_installer_url = installer_url.replace("%", "%%")
script = f"""@echo off script = fr"""@echo off
setlocal setlocal
set "INSTALLER_URL={escaped_installer_url}" set "INSTALLER_URL={escaped_installer_url}"
set "INSTALLER=%TEMP%\\install-sfera-windows-agent.ps1" set "INSTALLER=%TEMP%\install-sfera-windows-agent.ps1"
echo Downloading SFERA Windows Agent installer... echo Downloading SFERA Windows Agent installer...
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Invoke-WebRequest -UseBasicParsing -Uri $env:INSTALLER_URL -OutFile $env:INSTALLER" powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Invoke-WebRequest -UseBasicParsing -Uri $env:INSTALLER_URL -OutFile $env:INSTALLER"
if errorlevel 1 ( if errorlevel 1 (