我有這個(gè)模型管理員 -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 圖像但是當(dāng)我覆蓋語言過濾對象的 get_queryset 方法時(shí) - 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 圖像甚至前端查詢也會發(fā)生這種情況!有關(guān)詳細(xì)信息 - 我有大約 40 萬條記錄的數(shù)據(jù)庫表,這是模型 -
1 回答

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