From 2dd4f7b9721b201dc51cb2fb06d32cb1cb833458 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sat, 24 May 2025 17:53:57 +0200 Subject: [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 --- searx/cache.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'searx/cache.py') 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: -- cgit v1.2.3