From 848c8d0544eb0138da4414a750f79b22883f91b2 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sun, 25 May 2025 10:40:57 +0200 Subject: [mod] data: implement a simple currencies (SQL) database (#4836) To reduce the memory footprint, this patch no longer loads the JSON data completely into memory. Instead, there is an SQL database based on `ExpireCacheSQLite`. The class CurrenciesDB is a simple DB application that encapsulates the DB (queries and initialization) and provides convenient methods like `name_to_iso4217` and `iso4217_to_name`. Related: - https://github.com/searxng/searxng/discussions/1892 - https://github.com/searxng/searxng/pull/3458#issuecomment-2900807671 - https://github.com/searxng/searxng/pull/4650 Signed-off-by: Markus Heiser --- searxng_extra/update/update_currencies.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'searxng_extra/update') diff --git a/searxng_extra/update/update_currencies.py b/searxng_extra/update/update_currencies.py index 903bdcb44..288f0994e 100755 --- a/searxng_extra/update/update_currencies.py +++ b/searxng_extra/update/update_currencies.py @@ -15,9 +15,7 @@ import json from searx.locales import LOCALE_NAMES, locales_initialize from searx.engines import wikidata, set_loggers -from searx.data import data_dir - -DATA_FILE = data_dir / 'currencies.json' +from searx.data.currencies import CurrenciesDB set_loggers(wikidata, 'wikidata') locales_initialize() @@ -149,7 +147,7 @@ def main(): if len(db['names'][name]) == 1: db['names'][name] = db['names'][name][0] - with DATA_FILE.open('w', encoding='utf8') as f: + with CurrenciesDB.json_file.open('w', encoding='utf8') as f: json.dump(db, f, indent=4, sort_keys=True, ensure_ascii=False) -- cgit v1.2.3