我有這個模型管理員 -class NewsAdmin(ImageWidgetAdmin): image_fields = ['featured_image'] list_per_page = 20 list_display = ('heading', 'category', 'status', 'is_active', 'created_at', 'published_at', 'created_by', 'published_by') list_editable = ('category', 'status', 'is_active') list_filter = ('published_at', 'created_at', 'status', 'is_active', 'created_by', 'published_by',) search_fields = ('heading', 'category', 'tags', 'source') actions = [enable_object, disable_object, status_draft, status_private, status_public] actions_on_bottom = True加載最多只需要 400 毫秒。這是 django-debug-toolbar 圖像 -沒有 get_queryset 的 djdt 圖像但是當我覆蓋語言過濾對象的 get_queryset 方法時 - def get_queryset(self, request): queryset = super(NewsAdmin, self).get_queryset(request) return queryset.filter(language=request.LANGUAGE_CODE)大約需要 17-18 秒,這太瘋狂了??!這是 django-debug-toolbar 圖像 -帶有 get_queryset 的 djdt 圖像甚至前端查詢也會發生這種情況!有關詳細信息 - 我有大約 40 萬條記錄的數據庫表,這是模型 -
1 回答

湖上湖
TA貢獻2003條經驗 獲得超2個贊
您正在過濾沒有索引的字段。表越大,數據庫掃描每一行所需的時間就越長。更改您的字段定義以允許索引并處理遷移。
language = models.CharField(max_length=10, choices=LANGUAGES, default='bn' db_index=True)
添加回答
舉報
0/150
提交
取消