diff options
author | Dalf <alex@al-f.net> | 2019-11-15 09:31:37 +0100 |
---|---|---|
committer | Dalf <alex@al-f.net> | 2019-11-15 09:33:15 +0100 |
commit | 85b37233458c21b775bf98568c0a5c9260aa14fe (patch) | |
tree | 4b79330d170d3f8dbc0c52dadbfef429c31b2187 /searx/engines/wikidata.py | |
parent | 42d5e2c02cd4715a0e09411efbb249ef5d8defed (diff) | |
download | searxng-85b37233458c21b775bf98568c0a5c9260aa14fe.tar.gz searxng-85b37233458c21b775bf98568c0a5c9260aa14fe.zip |
[mod] speed optimization
compile XPath only once
avoid redundant call to urlparse
get_locale(webapp.py): avoid useless call to request.accept_languages.best_match
Diffstat (limited to 'searx/engines/wikidata.py')
-rw-r--r-- | searx/engines/wikidata.py | 18 |
1 files changed, 1 insertions, 17 deletions
diff --git a/searx/engines/wikidata.py b/searx/engines/wikidata.py index 5ea2b9958..e913b3915 100644 --- a/searx/engines/wikidata.py +++ b/searx/engines/wikidata.py @@ -16,7 +16,7 @@ from searx.poolrequests import get from searx.engines.xpath import extract_text from searx.engines.wikipedia import _fetch_supported_languages, supported_languages_url from searx.url_utils import urlencode -from searx.utils import match_language +from searx.utils import match_language, eval_xpath from json import loads from lxml.html import fromstring @@ -57,22 +57,6 @@ language_fallback_xpath = '//sup[contains(@class,"wb-language-fallback-indicator calendar_name_xpath = './/sup[contains(@class,"wb-calendar-name")]' media_xpath = value_xpath + '//div[contains(@class,"commons-media-caption")]//a' -# xpath_cache -xpath_cache = {} - - -def get_xpath(xpath_str): - result = xpath_cache.get(xpath_str, None) - if not result: - result = etree.XPath(xpath_str) - xpath_cache[xpath_str] = result - return result - - -def eval_xpath(element, xpath_str): - xpath = get_xpath(xpath_str) - return xpath(element) - def get_id_cache(result): id_cache = {} |