[11/11] Fetch maintainer information in one query

Message ID 20180810080106.10714-12-stewart@linux.ibm.com
State Accepted
Headers show
Series
  • Performance for ALL THE THINGS!
Related show

Commit Message

Stewart Smith Aug. 10, 2018, 8:01 a.m.
Viewing the /project/ page lists maintainers. Prior to this patch,
this was done in one query to fetch the maintainer IDs, and then one
query per mainatiner to get the name/email address.

Now, with this patch, it's all in one query (yay joins) and saves
a few ms of database queries for displaying the page.

Realistically, this doesn't save us too much time as counting how many
patches are there takes 99% of the database time for this page.

Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
---
 patchwork/views/project.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stephen Finucane Aug. 31, 2018, 2:17 p.m. | #1
On Fri, 2018-08-10 at 18:01 +1000, Stewart Smith wrote:
> Viewing the /project/ page lists maintainers. Prior to this patch,
> this was done in one query to fetch the maintainer IDs, and then one
> query per mainatiner to get the name/email address.
> 
> Now, with this patch, it's all in one query (yay joins) and saves
> a few ms of database queries for displaying the page.
> 
> Realistically, this doesn't save us too much time as counting how many
> patches are there takes 99% of the database time for this page.
> 
> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>

Agree with all the points above.

Reviewed-by: Stephen Finucane <stephen@that.guru>

Stephen

> ---
>  patchwork/views/project.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/patchwork/views/project.py b/patchwork/views/project.py
> index 2a75242a06af..fdcc6626eda1 100644
> --- a/patchwork/views/project.py
> +++ b/patchwork/views/project.py
> @@ -66,7 +66,7 @@ def project_detail(request, project_id):
>      context = {
>          'project': project,
>          'maintainers': User.objects.filter(
> -            profile__maintainer_projects=project),
> +            profile__maintainer_projects=project).select_related('profile'),
>          'n_patches': n_patches[False],
>          'n_archived_patches': n_patches[True],
>          'enable_xmlrpc': settings.ENABLE_XMLRPC,

Patch

diff --git a/patchwork/views/project.py b/patchwork/views/project.py
index 2a75242a06af..fdcc6626eda1 100644
--- a/patchwork/views/project.py
+++ b/patchwork/views/project.py
@@ -66,7 +66,7 @@  def project_detail(request, project_id):
     context = {
         'project': project,
         'maintainers': User.objects.filter(
-            profile__maintainer_projects=project),
+            profile__maintainer_projects=project).select_related('profile'),
         'n_patches': n_patches[False],
         'n_archived_patches': n_patches[True],
         'enable_xmlrpc': settings.ENABLE_XMLRPC,