mirror of
https://github.com/searxng/searxng.git
synced 2025-12-26 21:50:02 +00:00
[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>
This commit is contained in:
committed by
Markus Heiser
parent
4f4de3fc87
commit
18a58943cc
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user