Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N+1 requêtes SQL #6412

Closed
philippemilink opened this issue Oct 31, 2022 · 0 comments · Fixed by #6490
Closed

N+1 requêtes SQL #6412

philippemilink opened this issue Oct 31, 2022 · 0 comments · Fixed by #6490
Labels
C-Back Concerne le back-end Django S-BUG Corrige un problème

Comments

@philippemilink
Copy link
Member

philippemilink commented Oct 31, 2022

Description du bug

Sentry semble maintenant rapporter les problèmes du style N+1 requêtes SQL.

Voici ce qu'il a trouvé :

  • route /forums/sujet/{topic_pk}/{topic_slug}/ : les requêtes SQL répétées sont :
    SELECT `auth_user`.`id`, `auth_user`.`password`, `auth_user`.`last_login`, `auth_user`.`is_superuser`, `auth_user`.`username`, `auth_user`.`first_name`, `auth_user`.`last_name`, `auth_user`.`email`, `auth_user`.`is_staff`, `auth_user`.`is_active`, `auth_user`.`date_joined` FROM `auth_user` WHERE `auth_user`.`id` = %s LIMIT 21
    SELECT `utils_comment`.`id`, `utils_comment`.`author_id`, `utils_comment`.`editor_id`, `utils_comment`.`ip_address`, `utils_comment`.`position`, `utils_comment`.`text`, `utils_comment`.`text_html`, `utils_comment`.`like`, `utils_comment`.`dislike`, `utils_comment`.`pubdate`, `utils_comment`.`update`, `utils_comment`.`update_index_date`, `utils_comment`.`is_visible`, `utils_comment`.`text_hidden`, `utils_comment`.`hat_id`, `utils_comment`.`is_potential_spam`, `forum_post`.`comment_ptr_id`, `forum_post`.`es_flagged`, `forum_post`.`es_already_indexed`, `forum_post`.`topic_id`, `forum_post`.`is_useful` FROM `forum_post` INNER JOIN `utils_comment` ON (`forum_post`.`comment_ptr_id` = `utils_comment`.`id`) WHERE `forum_post`.`comment_ptr_id` = %s LIMIT 21
  • route /forums/messages/{user_pk}/ : la requête SQL répétée est :
    SELECT `forum_topic`.`id`, `forum_topic`.`es_flagged`, `forum_topic`.`es_already_indexed`, `forum_topic`.`title`, `forum_topic`.`subtitle`, `forum_topic`.`forum_id`, `forum_topic`.`author_id`, `forum_topic`.`last_message_id`, `forum_topic`.`pubdate`, `forum_topic`.`update_index_date`, `forum_topic`.`solved_by_id`, `forum_topic`.`is_locked`, `forum_topic`.`is_sticky`, `forum_topic`.`github_issue`, `forum_topic`.`github_repository_name` FROM `forum_topic` WHERE `forum_topic`.`id` = %s LIMIT 21
  • route /pages/contact/ : la requête SQL répétée est :
    SELECT `member_profile`.`id`, `member_profile`.`user_id`, `member_profile`.`username_skeleton`, `member_profile`.`last_ip_address`, `member_profile`.`site`, `member_profile`.`show_email`, `member_profile`.`avatar_url`, `member_profile`.`biography`, `member_profile`.`karma`, `member_profile`.`sign`, `member_profile`.`licence_id`, `member_profile`.`github_token`, `member_profile`.`show_sign`, `member_profile`.`hide_forum_activity`, `member_profile`.`is_hover_enabled`, `member_profile`.`allow_temp_visual_changes`, `member_profile`.`show_markdown_help`, `member_profile`.`email_for_answer`, `member_profile`.`email_for_new_mp`, `member_profile`.`can_read`, `member_profile`.`end_ban_read`, `member_profile`.`can_write`, `member_profile`.`end_ban_write`, `member_profile`.`last_visit` FROM `member_profile` WHERE `member_profile`.`user_id` = %s LIMIT 21
  • route /contenus/modifier-objectifs/ : la requête SQL répétée est :
    SELECT `tutorialv2_goal`.`id`, `tutorialv2_goal`.`name`, `tutorialv2_goal`.`description`, `tutorialv2_goal`.`position`, `tutorialv2_goal`.`slug` FROM `tutorialv2_goal` INNER JOIN `tutorialv2_publishablecontent_goals` ON (`tutorialv2_goal`.`id` = `tutorialv2_publishablecontent_goals`.`goal_id`) WHERE `tutorialv2_publishablecontent_goals`.`publishablecontent_id` = %s
  • route /forums/sujets/tag/{tag_slug}/ : plusieurs requêtes sont répétées
  • route /forums/{cat_slug}/{forum_slug}/ : plusieurs requêtes sont répétées
  • route /forums/{slug}/ : plusieurs requêtes sont répétées
  • route /bibliotheque/ : plusieurs requêtes sont répétées
  • route /billets/ : plusieurs requêtes sont répétées
  • route /validations/: plusieurs requêtes sont répétées

On peut probablement les voir dans la barre de debug de Django.

Il y a sans doute des jointures à rajouter pour éviter ces nombreuses requêtes.

@philippemilink philippemilink added S-BUG Corrige un problème C-Back Concerne le back-end Django labels Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Back Concerne le back-end Django S-BUG Corrige un problème
Projects
Status: Clos
Development

Successfully merging a pull request may close this issue.

1 participant