Skip to content

armgit / mwmbl

Public Imported from GitHub
0

An open source, non-profit web search engine

Manually use cache instead of broken decorator

Daoud Clarkeb512b7fc915f
diff --git a/mwmbl/search_setup.py b/mwmbl/search_setup.py
index 9105886..ddb0a68 100644
--- a/mwmbl/search_setup.py
+++ b/mwmbl/search_setup.py
@@ -3,7 +3,7 @@ import pickle
from pathlib import Path
from django.conf import settings
-from django_cache_decorator import django_cache_decorator
+from django.core.cache import cache
from redis import Redis
from mwmbl.indexer.batch_cache import BatchCache
@@ -14,9 +14,15 @@ from mwmbl.tinysearchengine.indexer import TinyIndex, Document
from mwmbl.tinysearchengine.ltr_rank import LTRRanker
-@django_cache_decorator(time=300)
+CURATED_DOMAINS_CACHE_KEY = "curated-domains"
+CURATED_DOMAINS_CACHE_TIMEOUT = 300
+
+
def get_curated_domains() -> set[str]:
- curated_domains = set(DomainSubmission.objects.filter(status="APPROVED").values_list('name', flat=True))
+ curated_domains = cache.get(CURATED_DOMAINS_CACHE_KEY)
+ if curated_domains is None:
+ curated_domains = set(DomainSubmission.objects.filter(status="APPROVED").values_list('name', flat=True))
+ cache.set(CURATED_DOMAINS_CACHE_KEY, curated_domains, CURATED_DOMAINS_CACHE_TIMEOUT)
return curated_domains
diff --git a/poetry.lock b/poetry.lock
index 0f4697a..0762427 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -1,4 +1,4 @@
-# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand.
+# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand.
[[package]]
name = "anyio"
@@ -563,16 +563,6 @@ requests-oauthlib = ">=0.3.0"
mfa = ["qrcode (>=7.0.0)"]
saml = ["python3-saml (>=1.15.0,<2.0.0)"]
-[[package]]
-name = "django-cache-decorator"
-version = "0.4.1"
-description = "Easily add caching to functions within a django project."
-optional = false
-python-versions = "*"
-files = [
- {file = "django-cache-decorator-0.4.1.tar.gz", hash = "sha256:cbaf919b57b0095f4a06a1b356a339cc8c158eae65c6229a1255787c1510b3cc"},
-]
-
[[package]]
name = "django-htmx"
version = "1.18.0"
@@ -3020,4 +3010,4 @@ indexer = ["Levenshtein", "beautifulsoup4", "idna", "langdetect", "pyarrow", "py
[metadata]
lock-version = "2.0"
python-versions = ">=3.10,<3.11"
-content-hash = "e97ead7ee7a04babb13f57ac86702f7c6f20bb51ae2b79604f0f06df3916182e"
+content-hash = "d44a4f54a5a5ee4fd70ce03c11bd761dc2e8af94de206fd0423dc1fb128f0783"
diff --git a/pyproject.toml b/pyproject.toml
index 144ea99..0e0c107 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -48,7 +48,6 @@ objgraph = "^3.6.1"
psutil = "^6.0.0"
xgboost = "^2.1.0"
pydistinct = "^0.6.4"
-django-cache-decorator = "^0.4.1"
[tool.poetry.extras]
indexer = [