Skip to content

Commit bb90743

Browse files
authored
Merge pull request #487 from liangliangyy/dev
performance es index bug修复
2 parents 3c2b5a2 + f4b984e commit bb90743

File tree

4 files changed

+50
-15
lines changed

4 files changed

+50
-15
lines changed

.github/workflows/django.yml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,46 @@ on:
2121
- '**/*.yml'
2222

2323
jobs:
24-
build:
24+
build-normal:
25+
runs-on: ubuntu-latest
26+
strategy:
27+
max-parallel: 4
28+
matrix:
29+
python-version: [ 3.6, 3.7, 3.8, 3.9 ]
30+
31+
steps:
32+
- name: Start MySQL
33+
uses: samin/[email protected]
34+
with:
35+
host port: 3306
36+
container port: 3306
37+
character set server: utf8mb4
38+
collation server: utf8mb4_general_ci
39+
mysql version: latest
40+
mysql root password: root
41+
mysql database: djangoblog
42+
mysql user: root
43+
mysql password: root
44+
45+
- uses: actions/checkout@v2
46+
- name: Set up Python ${{ matrix.python-version }}
47+
uses: actions/setup-python@v1
48+
with:
49+
python-version: ${{ matrix.python-version }}
50+
- name: Install Dependencies
51+
run: |
52+
python -m pip install --upgrade pip
53+
pip install -r requirements.txt
54+
- name: Run Tests
55+
env:
56+
DJANGO_MYSQL_PASSWORD: root
57+
DJANGO_MYSQL_HOST: 127.0.0.1
58+
run: |
59+
python manage.py makemigrations
60+
python manage.py migrate
61+
python manage.py test
2562
63+
build-with-es:
2664
runs-on: ubuntu-latest
2765
strategy:
2866
max-parallel: 4

.github/workflows/docker.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,4 @@ jobs:
2828
with:
2929
context: .
3030
push: true
31-
platforms: |
32-
linux/amd64
33-
linux/arm64
34-
linux/arm/v7
35-
linux/arm/v6
36-
linux/386
3731
tags: ${{ secrets.DOCKERHUB_USERNAME }}/djangoblog:latest

blog/documents.py

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

9595

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

103111
@staticmethod
104112
def create(url, time_taken, log_datetime, useragent, ip):
105-
from elasticsearch import Elasticsearch
106-
client = Elasticsearch(settings.ELASTICSEARCH_DSL['default']['hosts'])
107-
108-
res = client.indices.exists(index="performance")
109-
if not res:
110-
ElapsedTimeDocument.init()
113+
ElaspedTimeDocumentManager.build_index()
111114
ua = UserAgent()
112115
ua.browser = UserAgentBrowser()
113116
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)