add Python library diskcache
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s

This commit is contained in:
Thomas Peetz
2026-09-17 16:37:02 +02:00
parent 8a5bc7873a
commit c1d913e36b
4 changed files with 27 additions and 7 deletions
+7 -1
View File
@@ -4,6 +4,7 @@ from logging import Logger
from pathlib import Path
from typing import Dict, List, Optional
from uuid import UUID
from diskcache import Index
from platformdirs import PlatformDirs
import requests
@@ -142,12 +143,15 @@ class Server:
self.token = str(token)
self.token_type = str(token_type)
def request(self, log: Logger, table: str, param: Optional[Option] = None):
def request(self, log: Logger, table: str, index: Index, param: Optional[Option] = None):
"""
Requests data from Kontor-API instance by given table and optional parameters.
"""
if not param:
url: str = f"{self.url}/{MAPPING[table]}"
if table in index:
log.info("use chached %s", table)
return index[table]
else:
url: str = f"{self.url}/{MAPPING[table]}{str(param)}"
headers: Dict[str, str] = {"Authorization": f"Bearer {self.token}"}
@@ -160,6 +164,8 @@ class Server:
if response.status_code == 404:
raise EndPointNotAvailableException
data = response.json()
log.info("cache values of %s", table)
index[table] = data
return data
def update(self, log: Logger, table: str, item_id: UUID, file_info: dict):