From 3b5c50c5a199c3db817b42f24f74805827c2babc Mon Sep 17 00:00:00 2001 From: liangliang Date: Wed, 21 Jul 2021 21:27:00 +0800 Subject: [PATCH] =?UTF-8?q?performance=20es=20index=20bug=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blog/documents.py | 16 +++++++++------- blog/management/commands/build_index.py | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/blog/documents.py b/blog/documents.py index 5b55cf2..5b20d0b 100644 --- a/blog/documents.py +++ b/blog/documents.py @@ -92,7 +92,15 @@ class ElapsedTimeDocument(Document): doc_type = 'ElapsedTime' -class ElaspedTimeDocumentManager(): +class ElaspedTimeDocumentManager: + @staticmethod + def build_index(): + from elasticsearch import Elasticsearch + client = Elasticsearch(settings.ELASTICSEARCH_DSL['default']['hosts']) + res = client.indices.exists(index="performance") + if not res: + ElapsedTimeDocument.init() + @staticmethod def delete_index(): from elasticsearch import Elasticsearch @@ -101,12 +109,6 @@ class ElaspedTimeDocumentManager(): @staticmethod def create(url, time_taken, log_datetime, useragent, ip): - from elasticsearch import Elasticsearch - client = Elasticsearch(settings.ELASTICSEARCH_DSL['default']['hosts']) - - res = client.indices.exists(index="performance") - if not res: - ElapsedTimeDocument.init() ua = UserAgent() ua.browser = UserAgentBrowser() ua.browser.Family = useragent.browser.family diff --git a/blog/management/commands/build_index.py b/blog/management/commands/build_index.py index 1c5a5b1..0391cc3 100644 --- a/blog/management/commands/build_index.py +++ b/blog/management/commands/build_index.py @@ -23,8 +23,8 @@ class Command(BaseCommand): def handle(self, *args, **options): if ELASTICSEARCH_ENABLED: + ElaspedTimeDocumentManager.build_index() manager = ElapsedTimeDocument() - ElaspedTimeDocumentManager.delete_index() manager.init() manager = ArticleDocumentManager() manager.delete_index()