[Patchew-devel] [PATCH] cut number of queries for anonymous browsing
Paolo Bonzini
pbonzini at redhat.com
Wed May 2 15:27:50 UTC 2018
For a single request to http://127.0.0.1:8000/QEMU/ we get 78
SQL queries, and 50 of them are checking whether the project is
maintained by the current logged in user. Certainly caching the
answer is a possibility, but really an anonymous user is never
going to be a maintainer. Adding the check to maintained_by
cuts the queries from 78 to 28 and the processing time from
12 to 7 ms.
Signed-off-by: Paolo Bonzini <pbonzini at redhat.com>
---
api/models.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/api/models.py b/api/models.py
index 4cc2b74..504f2c7 100644
--- a/api/models.py
+++ b/api/models.py
@@ -131,6 +131,8 @@ class Project(models.Model):
return Message.objects.series_heads(project=self.name).count()
def maintained_by(self, user):
+ if user.is_anonymous:
+ return False
if user.is_superuser:
return True
if self.maintainers.filter(id=user.id).exists():
--
2.17.0
More information about the Patchew-devel
mailing list