Skip to content

Commit e52802c

Browse files
authored
Merge pull request #69 from nineaiyu/dev
perf: 优化代码
2 parents 8ef389f + 54564cf commit e52802c

File tree

9 files changed

+90
-70
lines changed

9 files changed

+90
-70
lines changed

common/core/config.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,6 @@ def FILE_UPLOAD_SIZE(self):
172172
def PICTURE_UPLOAD_SIZE(self):
173173
return self.get_value('PICTURE_UPLOAD_SIZE', settings.PICTURE_UPLOAD_SIZE)
174174

175-
@property
176-
def EXPORT_MAX_LIMIT(self):
177-
return self.get_value('EXPORT_MAX_LIMIT', 20000)
178-
179175

180176
class MessagePushConfCache(ConfigCacheBase):
181177
def __init__(self, *args, **kwargs):

common/core/modelset.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
# date : 6/2/2023
77
import itertools
88
import json
9+
import math
910
import uuid
1011
from hashlib import md5
1112
from typing import Callable
1213

13-
import math
1414
from django.conf import settings
1515
from django.db import transaction
1616
from django.forms.widgets import SelectMultiple, DateTimeInput
@@ -41,15 +41,17 @@
4141
logger = get_logger(__name__)
4242

4343

44-
def run_view_by_celery_task(view, request, kwargs, list_data, batch_length=100):
44+
def run_view_by_celery_task(view, request, kwargs, data, batch_length=100):
4545
task = kwargs.get("task", request.query_params.get('task', 'true').lower() in ['true', '1', 'yes']) # 默认为任务异步导入
4646
if task:
4747
view_str = f"{view.__class__.__module__}.{view.__class__.__name__}"
4848
meta = request.META
4949
task_id = uuid.uuid4()
50-
meta["task_count"] = math.ceil(len(list_data) / batch_length)
50+
if isinstance(data, dict):
51+
data = [data]
52+
meta["task_count"] = math.ceil(len(data) / batch_length)
5153
meta["action"] = view.action
52-
for index, batch in enumerate(itertools.batched(list_data, batch_length)):
54+
for index, batch in enumerate(itertools.batched(data, batch_length)):
5355
meta["task_id"] = f"{task_id}_{index}"
5456
meta["task_index"] = index
5557
res = background_task_view_set_job.apply_async(args=(view_str, meta, json.dumps(batch), view.action_map),

common/drf/renders/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from rest_framework.renderers import BaseRenderer
1111
from rest_framework.utils import encoders, json
1212

13-
from common.core.config import SysConfig
1413
from common.core.fields import LabeledChoiceField, BasePrimaryKeyRelatedField, PhoneField
1514
from common.utils import get_logger
1615
from common.utils.timezone import local_now
@@ -89,7 +88,7 @@ def process_data(self, data):
8988
results = [results[0]] if results else results
9089
else:
9190
# 限制数据数量
92-
results = results[:SysConfig.EXPORT_MAX_LIMIT]
91+
results = results[:settings.EXPORT_MAX_LIMIT]
9392
# 会将一些 UUID 字段转化为 string
9493
results = json.loads(json.dumps(results, cls=encoders.JSONEncoder))
9594
return results

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ services:
3232
volumes:
3333
- ${VOLUME_DIR:-../}/xadmin-postgresql/data:/var/lib/postgresql/data
3434
healthcheck:
35-
test: "pg_isready -q -U $$POSTGRES_USER"
35+
test: "pg_isready -q -U $$POSTGRES_USER -d $$POSTGRES_DB"
3636
interval: 10s
3737
timeout: 5s
3838
retries: 3

locale/en/LC_MESSAGES/django.po

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2024-11-27 11:21+0800\n"
11+
"POT-Creation-Date: 2024-11-28 10:19+0800\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -23,7 +23,7 @@ msgid ""
2323
"<h3>Celery flower service unavailable. Please contact the administrator</h3>"
2424
msgstr ""
2525

26-
#: common/core/auth.py:25 common/core/filter.py:205 common/core/filter.py:213
26+
#: common/core/auth.py:25 common/core/filter.py:204 common/core/filter.py:212
2727
#: common/core/permission.py:126
2828
msgid "Unauthorized authentication"
2929
msgstr ""
@@ -97,31 +97,31 @@ msgstr ""
9797
msgid "Data ownership department"
9898
msgstr ""
9999

100-
#: common/core/modelset.py:58
100+
#: common/core/modelset.py:60
101101
msgid "Task add success"
102102
msgstr ""
103103

104-
#: common/core/modelset.py:113
104+
#: common/core/modelset.py:115
105105
msgid "Image size cannot exceed {}"
106106
msgstr ""
107107

108-
#: common/core/modelset.py:116
108+
#: common/core/modelset.py:118
109109
msgid "Wrong image type, the type should be {}"
110110
msgstr ""
111111

112-
#: common/core/modelset.py:139
112+
#: common/core/modelset.py:141
113113
msgid "Sorting saved successfully"
114114
msgstr ""
115115

116-
#: common/core/modelset.py:410
116+
#: common/core/modelset.py:412
117117
msgid "Operation successful. Batch deleted {} data"
118118
msgstr ""
119119

120-
#: common/core/modelset.py:523
120+
#: common/core/modelset.py:525
121121
msgid "Operation successful. Import {} data"
122122
msgstr ""
123123

124-
#: common/core/modelset.py:524 system/utils/auth.py:104
124+
#: common/core/modelset.py:526 system/utils/auth.py:104
125125
#: system/utils/modelset.py:57 system/views/auth/register.py:69
126126
#: system/views/auth/reset.py:47 system/views/auth/verify_code.py:139
127127
msgid "Operation failed. Abnormal data"
@@ -163,90 +163,90 @@ msgstr ""
163163
msgid "Invalid excel file {}"
164164
msgstr ""
165165

166-
#: common/drf/renders/base.py:148
166+
#: common/drf/renders/base.py:147
167167
msgid "Yes/No"
168168
msgstr ""
169169

170-
#: common/drf/renders/base.py:151
170+
#: common/drf/renders/base.py:150
171171
msgid "Text, max length {}"
172172
msgstr ""
173173

174-
#: common/drf/renders/base.py:153
174+
#: common/drf/renders/base.py:152
175175
msgid "Long text, no length limit"
176176
msgstr ""
177177

178-
#: common/drf/renders/base.py:155
178+
#: common/drf/renders/base.py:154
179179
msgid "Number, min {}, max {}"
180180
msgstr ""
181181

182-
#: common/drf/renders/base.py:157
182+
#: common/drf/renders/base.py:156
183183
msgid "Float, min {}, max {}"
184184
msgstr ""
185185

186-
#: common/drf/renders/base.py:159
186+
#: common/drf/renders/base.py:158
187187
msgid "Decimal, min {}, max {}, max_digits {}, decimal_places {}"
188188
msgstr ""
189189

190-
#: common/drf/renders/base.py:164
190+
#: common/drf/renders/base.py:163
191191
msgid "Datetime format {}"
192192
msgstr ""
193193

194-
#: common/drf/renders/base.py:166
194+
#: common/drf/renders/base.py:165
195195
#: system/templates/notify/msg_rest_password_success.html:9
196196
msgid "IP"
197197
msgstr ""
198198

199-
#: common/drf/renders/base.py:170
199+
#: common/drf/renders/base.py:169
200200
msgid ""
201201
"Choices, format name(value), name is optional for human read, value is "
202202
"requisite, options {}"
203203
msgstr ""
204204

205-
#: common/drf/renders/base.py:173
205+
#: common/drf/renders/base.py:172
206206
msgid "Choices, options {}"
207207
msgstr ""
208208

209-
#: common/drf/renders/base.py:175
209+
#: common/drf/renders/base.py:174
210210
msgid "Phone number, format +8612345678901"
211211
msgstr ""
212212

213-
#: common/drf/renders/base.py:177
213+
#: common/drf/renders/base.py:176
214214
msgid "Label, format [\"key:value\"]"
215215
msgstr ""
216216

217-
#: common/drf/renders/base.py:179
217+
#: common/drf/renders/base.py:178
218218
msgid ""
219219
"Object, format name(id), name is optional for human read, id is requisite"
220220
msgstr ""
221221

222-
#: common/drf/renders/base.py:181
222+
#: common/drf/renders/base.py:180
223223
msgid "Object, format id"
224224
msgstr ""
225225

226-
#: common/drf/renders/base.py:185
226+
#: common/drf/renders/base.py:184
227227
msgid ""
228228
"Objects, format [\"name(id)\", ...], name is optional for human read, id is "
229229
"requisite"
230230
msgstr ""
231231

232-
#: common/drf/renders/base.py:187
232+
#: common/drf/renders/base.py:186
233233
msgid ""
234234
"Labels, format [\"key:value\", ...], if label not exists, will create it"
235235
msgstr ""
236236

237-
#: common/drf/renders/base.py:189
237+
#: common/drf/renders/base.py:188
238238
msgid "Objects, format [\"id\", ...]"
239239
msgstr ""
240240

241-
#: common/drf/renders/base.py:195
241+
#: common/drf/renders/base.py:194
242242
msgid "JSON"
243243
msgstr ""
244244

245-
#: common/drf/renders/base.py:197
245+
#: common/drf/renders/base.py:196
246246
msgid "UUID4"
247247
msgstr ""
248248

249-
#: common/drf/renders/base.py:302
249+
#: common/drf/renders/base.py:301
250250
msgid ""
251251
"{} - The encryption password has not been set - please go to personal "
252252
"information -> file encryption password to set the encryption password"
@@ -719,6 +719,14 @@ msgstr ""
719719
msgid "Data permissions are used to authorize access to data"
720720
msgstr ""
721721

722+
#: settings/serializers/basic.py:39
723+
msgid "Export max limit"
724+
msgstr ""
725+
726+
#: settings/serializers/basic.py:40
727+
msgid "Limit the maximum number of rows of exported data"
728+
msgstr ""
729+
722730
#: settings/serializers/email.py:13
723731
msgid "Enable Email Service (Email)"
724732
msgstr ""

0 commit comments

Comments
 (0)