Skip to content

Commit 3b5c50c

Browse files
committed
performance es index bug修复
1 parent fa7fcc3 commit 3b5c50c

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

blog/documents.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,15 @@ class Meta:
9292
doc_type = 'ElapsedTime'
9393

9494

95-
class ElaspedTimeDocumentManager():
95+
class ElaspedTimeDocumentManager:
96+
@staticmethod
97+
def build_index():
98+
from elasticsearch import Elasticsearch
99+
client = Elasticsearch(settings.ELASTICSEARCH_DSL['default']['hosts'])
100+
res = client.indices.exists(index="performance")
101+
if not res:
102+
ElapsedTimeDocument.init()
103+
96104
@staticmethod
97105
def delete_index():
98106
from elasticsearch import Elasticsearch
@@ -101,12 +109,6 @@ def delete_index():
101109

102110
@staticmethod
103111
def create(url, time_taken, log_datetime, useragent, ip):
104-
from elasticsearch import Elasticsearch
105-
client = Elasticsearch(settings.ELASTICSEARCH_DSL['default']['hosts'])
106-
107-
res = client.indices.exists(index="performance")
108-
if not res:
109-
ElapsedTimeDocument.init()
110112
ua = UserAgent()
111113
ua.browser = UserAgentBrowser()
112114
ua.browser.Family = useragent.browser.family

blog/management/commands/build_index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class Command(BaseCommand):
2323

2424
def handle(self, *args, **options):
2525
if ELASTICSEARCH_ENABLED:
26+
ElaspedTimeDocumentManager.build_index()
2627
manager = ElapsedTimeDocument()
27-
ElaspedTimeDocumentManager.delete_index()
2828
manager.init()
2929
manager = ArticleDocumentManager()
3030
manager.delete_index()

0 commit comments

Comments
 (0)