summaryrefslogtreecommitdiff
path: root/searx/cache.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2025-05-24 17:53:57 +0200
committerBnyro <bnyro@tutanota.com>2025-06-23 22:12:18 +0200
commit2dd4f7b9721b201dc51cb2fb06d32cb1cb833458 (patch)
treefe74795a1a6fa06bf5761083a1e9c57428be1b3c /searx/cache.py
parent58c10f758b09affda1a15c105e7ce86f3a3bdd3a (diff)
[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>
Diffstat (limited to 'searx/cache.py')
-rw-r--r--searx/cache.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/searx/cache.py b/searx/cache.py
index 7ba5c8886..16386838f 100644
--- a/searx/cache.py
+++ b/searx/cache.py
@@ -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: