summaryrefslogtreecommitdiff
path: root/searx/data/currencies.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2025-09-24 19:34:03 +0200
committerMarkus Heiser <markus.heiser@darmarIT.de>2025-09-28 07:32:41 +0200
commit18a58943ccaa324b39232fa503462eb39f407399 (patch)
tree04b355ad60c205b28ea1083ea97abdfabea857ff /searx/data/currencies.py
parent4f4de3fc8743b3732834c5ffaa4a3e264d200e6c (diff)
[mod] ExpireCacheSQLite - implement .setmany() for bulk loading
[1] https://github.com/searxng/searxng/issues/5223#issuecomment-3328597147 Suggested-by: Ivan G <igabaldon@inetol.net> [1] Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/data/currencies.py')
-rw-r--r--searx/data/currencies.py19
1 files changed, 8 insertions, 11 deletions
diff --git a/searx/data/currencies.py b/searx/data/currencies.py
index 33aa9530c..538900762 100644
--- a/searx/data/currencies.py
+++ b/searx/data/currencies.py
@@ -6,10 +6,12 @@ __all__ = ["CurrenciesDB"]
import typing as t
import json
import pathlib
-import time
from .core import get_cache, log
+if t.TYPE_CHECKING:
+ from searx.cache import CacheRowType
+
@t.final
class CurrenciesDB:
@@ -33,19 +35,14 @@ class CurrenciesDB:
# in /tmp and will be rebuild during the reboot anyway
def load(self):
- _start = time.time()
log.debug("init searx.data.CURRENCIES")
with open(self.json_file, encoding="utf-8") as f:
data_dict: dict[str, dict[str, str]] = json.load(f)
- for key, value in data_dict["names"].items():
- self.cache.set(key=key, value=value, ctx=self.ctx_names, expire=None)
- for key, value in data_dict["iso4217"].items():
- self.cache.set(key=key, value=value, ctx=self.ctx_iso4217, expire=None)
- log.debug(
- "init searx.data.CURRENCIES added %s items in %s sec.",
- len(data_dict["names"]) + len(data_dict["iso4217"]),
- time.time() - _start,
- )
+
+ rows: "list[CacheRowType]" = [(k, v, None) for k, v in data_dict["names"].items()]
+ self.cache.setmany(rows, ctx=self.ctx_names)
+ rows = [(k, v, None) for k, v in data_dict["iso4217"].items()]
+ self.cache.setmany(rows, ctx=self.ctx_iso4217)
def name_to_iso4217(self, name: str) -> str | None:
self.init()