perf: 修改搜索

pull/12394/head
ibuler 11 months ago committed by Bryan
parent 55575e9f7f
commit 4d15e46ceb

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

@ -123,13 +123,28 @@ class LabelViewSet(OrgBulkModelViewSet):
class LabeledResourceViewSet(OrgBulkModelViewSet): class LabeledResourceViewSet(OrgBulkModelViewSet):
model = LabeledResource model = LabeledResource
filterset_fields = ("label__name", "label__value", "res_type", "res_id", "label") filterset_fields = ("label__name", "label__value", "res_type", "res_id", "label")
search_fields = filterset_fields search_fields = []
serializer_classes = { serializer_classes = {
'default': serializers.LabeledResourceSerializer, 'default': serializers.LabeledResourceSerializer,
} }
ordering_fields = ('res_type', 'date_created') 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): def get_queryset(self):
queryset = super().get_queryset() queryset = super().get_queryset()
queryset = queryset.order_by('res_type') queryset = queryset.order_by('res_type')
return queryset return queryset
def filter_queryset(self, queryset):
queryset = super().filter_queryset(queryset)
queryset = self.filter_search(queryset)
return queryset

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

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

Loading…
Cancel
Save