diff --git a/regcore/db/es.py b/regcore/db/es.py index 9edf422..18026d4 100644 --- a/regcore/db/es.py +++ b/regcore/db/es.py @@ -2,6 +2,7 @@ etc.), implemented using Elastic Search as a data store""" import logging +from cached_property import cached_property from django.conf import settings from pyelasticsearch import ElasticSearch from pyelasticsearch.exceptions import ElasticHttpNotFoundError @@ -18,8 +19,10 @@ def sanitize_doc_id(doc_id): class ESBase(object): """Shared code for Elastic Search storage models""" - def __init__(self): - self.es = ElasticSearch(settings.ELASTIC_SEARCH_URLS) + + @cached_property + def es(self): + return ElasticSearch(settings.ELASTIC_SEARCH_URLS) def safe_fetch(self, doc_type, es_id): """Attempt to retrieve a document from Elastic Search. diff --git a/setup.py b/setup.py index 84016e8..d9ea8eb 100644 --- a/setup.py +++ b/setup.py @@ -7,6 +7,7 @@ packages=find_packages(), include_package_data=True, install_requires=[ + 'cached_property', 'django>=1.8,<1.12', 'django-mptt', 'jsonschema',