@sportik174

Почему запрос выполняется медленно в Django?

Есть такой запрос:

pcollections = PCollection.objects.filter(
		product__category__title__in = filter_items_active['categories_get'] ,
		product__color__title__in = filter_items_active['colors_get'] ,
		product__surface__title__in = filter_items_active['surfaces_get'] ,
		product__width_height__title__in = filter_items_active['width_heights_get'] ,
		product__price_type__title__in = filter_items_active['pricetypes_get'] ,
		fabrika__title__in = filter_items_active['fabriks_get'] ,
		product__appointment__title__in = filter_items_active['appointments_get'] ,
		product__premises__title__in = filter_items_active['premises_get'] ,
		fabrika__country__title__in = filter_items_active['countrys_get'] ,
		product__picture__title__in = filter_items_active['pictures_get'] ,
		product__form__title__in = filter_items_active['forms_get'] ,
		product__rectificate__in = filter_items_active['rectificate_get'] ,
		product__stock__in = filter_items_active['stock_get']
	).distinct()


Выполняется очень медленно. Подскажите как можно его оптимизировать?
  • Вопрос задан
  • 93 просмотра
Решения вопроса 1
@pyHammer
sportik174 ну тут стоит начать с того что у тебя происходит поиск по строке, догадываюсь что индексов на title нет.
Короче, тебе не следует делать так
product__category__title__in = filter_items_active['categories_get']

а следует делать вот так
product__category_id__in = filter_items_active['categories_get']

где в categories_get ты передаешь не строки, а id категорий и так со всеми остальными параметрами
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
26 апр. 2024, в 09:18
500 руб./в час
26 апр. 2024, в 06:46
1500 руб./в час
26 апр. 2024, в 05:31
1000 руб./за проект