Skip to content

Commit

Permalink
[#2606] Lazy load synomyns for Elasticsearch
Browse files Browse the repository at this point in the history
   - the synonyms need to be loaded after all the migrations
     have been run
  • Loading branch information
pi-sigma committed Jul 11, 2024
1 parent ab1950d commit e196a72
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/open_inwoner/search/utils.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import logging

from django.db.utils import DatabaseError
from django.utils.functional import lazy

from .models import Synonym

logger = logging.getLogger(__name__)


def load_synonyms() -> list:
"""used for ES"""
# todo should be refactored to be run after django migrations
try:
synonyms = [s.synonym_line() for s in Synonym.objects.all()]
except DatabaseError as exc:
logger.warning(f"Synonyms for elasticsearch were not loaded: {exc}")
return []

return synonyms
"""
Lazy load synonyms for Elasticsearch
"""

def _load_synonyms():
try:
synonyms = [s.synonym_line() for s in Synonym.objects.all()]
except DatabaseError as exc:
logger.warning(f"Synonyms for elasticsearch were not loaded: {exc}")
return []

return synonyms

return lazy(_load_synonyms)

0 comments on commit e196a72

Please sign in to comment.