feat(web): cache dashboard aggregations with version invalidation
This commit is contained in:
1 parent
91aa3e1f95
commit
9fd277c05f
15 files changed
+399
-30
No files matched your search
@@ -555,6 +555,43 @@ class Repository:
|
||||
(key, str(value)),
|
||||
))
|
||||
|
||||
# ------------------------------------------------------------ cache version
|
||||
|
||||
@staticmethod
|
||||
def cache_version_key(group: str) -> str:
|
||||
return f"cache:v:{group}"
|
||||
|
||||
def cache_version(self, group: str) -> int:
|
||||
def run(conn: sqlite3.Connection) -> int:
|
||||
row = conn.execute(
|
||||
"SELECT v FROM kv WHERE k = ?", (self.cache_version_key(group),)
|
||||
).fetchone()
|
||||
if row is None:
|
||||
return 0
|
||||
try:
|
||||
return int(str(row["v"]))
|
||||
except ValueError:
|
||||
return 0
|
||||
return self.db.read(run)
|
||||
|
||||
def bump_cache_version(self, group: str, *, now: int | None = None) -> int:
|
||||
now = self._now() if now is None else int(now)
|
||||
key = self.cache_version_key(group)
|
||||
|
||||
def run(conn: sqlite3.Connection) -> int:
|
||||
row = conn.execute("SELECT v FROM kv WHERE k = ?", (key,)).fetchone()
|
||||
try:
|
||||
value = int(str(row["v"])) + 1 if row is not None else 1
|
||||
except ValueError:
|
||||
value = 1
|
||||
conn.execute(
|
||||
"INSERT INTO kv(k, v) VALUES (?, ?) "
|
||||
"ON CONFLICT(k) DO UPDATE SET v = excluded.v",
|
||||
(key, str(value)),
|
||||
)
|
||||
return value
|
||||
return self.db.write(run)
|
||||
|
||||
# ------------------------------------------------------------ candidate
|
||||
|
||||
def known_aid(self, aid: int) -> bool:
|
||||
|
||||
Reference in new issue
Block a user