-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#2606] Lazy load synomyns for Elasticsearch
- the synonyms need to be loaded after all the migrations have been run
- Loading branch information
Showing
1 changed file
with
15 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |