Browse Source

perf: 修改搜索

pull/12394/head
ibuler 11 months ago committed by Bryan
parent
commit
4d15e46ceb
  1. 4
      apps/common/signal_handlers.py
  2. 17
      apps/labels/api.py
  3. 4
      apps/labels/models.py
  4. 2
      apps/locale/zh/LC_MESSAGES/django.po

4
apps/common/signal_handlers.py

@ -69,7 +69,7 @@ def digest_sql_query():
for query in queries:
sql = query['sql']
print(" # {}: {}".format(query['time'], sql))
# print(" # {}: {}".format(query['time'], sql))
if len(queries) < 3:
continue
print("- Table: {}".format(table_name))
@ -77,7 +77,7 @@ def digest_sql_query():
sql = query['sql']
if not sql or not sql.startswith('SELECT'):
continue
print('\t{}. {}'.format(i, sql))
# print('\t{}. {}'.format(i, sql))
logger.debug(">>> [{}] {}".format(method, path))
for name, counter in counters:

17
apps/labels/api.py

@ -123,13 +123,28 @@ class LabelViewSet(OrgBulkModelViewSet):
class LabeledResourceViewSet(OrgBulkModelViewSet):
model = LabeledResource
filterset_fields = ("label__name", "label__value", "res_type", "res_id", "label")
search_fields = filterset_fields
search_fields = []
serializer_classes = {
'default': serializers.LabeledResourceSerializer,
}
ordering_fields = ('res_type', 'date_created')
def filter_search(self, queryset):
keyword = self.request.query_params.get('search')
if not keyword:
return queryset
matched = []
for instance in queryset:
if keyword.lower() in str(instance.resource).lower():
matched.append(instance.id)
return queryset.filter(id__in=matched)
def get_queryset(self):
queryset = super().get_queryset()
queryset = queryset.order_by('res_type')
return queryset
def filter_queryset(self, queryset):
queryset = super().filter_queryset(queryset)
queryset = self.filter_search(queryset)
return queryset

4
apps/labels/models.py

@ -40,5 +40,5 @@ class LabeledResource(JMSOrgBaseModel):
unique_together = [('label', 'res_type', 'res_id', 'org_id')]
verbose_name = _('Labeled resource')
def __str__(self):
return '{} => {}'.format(self.label, self.resource)
# def __str__(self):
# return '{} => {}'.format(self.label, self.resource)

2
apps/locale/zh/LC_MESSAGES/django.po

@ -6904,7 +6904,7 @@ msgstr ""
"这些账号用于连接发布的应用,账号现在分为两种类型: <br/ >一种是专用的,每个用"
"户都有一个专用账号。 另一种是公共的,当应用不支持多开且专用的已经被使用时,会"
"使用公共账号连接; <br />注意: 如果不开启自动创建账号, 当前发布机仅能被指定标"
"签的资产调度到,默认不会放到调度池中"
"签的资产调度到,默认不会放到调度池中,且需要手动维护账号"
#: terminal/serializers/applet_host.py:92
msgid "The number of public accounts created automatically"

Loading…
Cancel
Save