diff options
Diffstat (limited to 'searx/data/currencies.py')
| -rw-r--r-- | searx/data/currencies.py | 19 |
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() |