mirror of
https://github.com/searxng/searxng.git
synced 2025-12-22 19:50:00 +00:00
[mod] data: implement a simple tracker URL (SQL) database
On demand, the tracker data is loaded directly into the cache, so that the maintenance of this data via PRs is no longer necessary. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
@@ -10,6 +10,7 @@ from __future__ import annotations
|
||||
__all__ = ["ExpireCacheCfg", "ExpireCacheStats", "ExpireCache", "ExpireCacheSQLite"]
|
||||
|
||||
import abc
|
||||
from collections.abc import Iterator
|
||||
import dataclasses
|
||||
import datetime
|
||||
import hashlib
|
||||
@@ -396,6 +397,20 @@ class ExpireCacheSQLite(sqlitedb.SQLiteAppl, ExpireCache):
|
||||
|
||||
return self.deserialize(row[0])
|
||||
|
||||
def pairs(self, ctx: str) -> Iterator[tuple[str, typing.Any]]:
|
||||
"""Iterate over key/value pairs from table given by argument ``ctx``.
|
||||
If ``ctx`` argument is ``None`` (the default), a table name is
|
||||
generated from the :py:obj:`ExpireCacheCfg.name`."""
|
||||
table = ctx
|
||||
self.maintenance()
|
||||
|
||||
if not table:
|
||||
table = self.normalize_name(self.cfg.name)
|
||||
|
||||
if table in self.table_names:
|
||||
for row in self.DB.execute(f"SELECT key, value FROM {table}"):
|
||||
yield row[0], self.deserialize(row[1])
|
||||
|
||||
def state(self) -> ExpireCacheStats:
|
||||
cached_items = {}
|
||||
for table in self.table_names:
|
||||
|
||||
Reference in New Issue
Block a user