Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core


Commits:
33d063c6 by Abhilash Raj at 2021-02-10T03:42:27+00:00
Reduce the number of database queries in UserManager.

Thanks to Daniel Silverstone for the suggestion and patch.

This reduces the number of queries made for get_user and get_address methods
and uses .one_or_none() instead of calling .count() and .one() separately which
results in two database lookups.

The performance improvement of this change is small, but does reduce the code a
bit too.

- - - - -
fad43095 by Abhilash Raj at 2021-02-10T03:42:27+00:00
Merge branch 'member-lookup' into 'master'

Reduce the number of database queries in UserManager.

Closes #700

See merge request mailman/mailman!777
- - - - -


2 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/model/usermanager.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -19,6 +19,11 @@ REST
 ----
 * Improve the speed of Members lookup via REST API. (Related to #700)
 
+
+Other
+-----
+* Reduce the number of database calls in UserManager. (Closes #700)
+
 .. _news-3.3.3:
 
 3.3.3


=====================================
src/mailman/model/usermanager.py
=====================================
@@ -82,10 +82,10 @@ class UserManager:
     @dbconnection
     def get_user(self, store, email):
         """See `IUserManager`."""
-        addresses = store.query(Address).filter_by(email=email.lower())
-        if addresses.count() == 0:
+        address = self.get_address(email)
+        if address is None:
             return None
-        return addresses.one().user
+        return address.user
 
     @dbconnection
     def get_user_by_id(self, store, user_id):
@@ -138,10 +138,8 @@ class UserManager:
     @dbconnection
     def get_address(self, store, email):
         """See `IUserManager`."""
-        addresses = store.query(Address).filter_by(email=email.lower())
-        if addresses.count() == 0:
-            return None
-        return addresses.one()
+        return store.query(
+            Address).filter_by(email=email.lower()).one_or_none()
 
     @property
     @dbconnection



View it on GitLab: 
https://gitlab.com/mailman/mailman/-/compare/d6e7bd8367ad80135f49747f70a7f26d96585bde...fad43095d2665a0b37f9a5a4826016d15c3ef15c

-- 
View it on GitLab: 
https://gitlab.com/mailman/mailman/-/compare/d6e7bd8367ad80135f49747f70a7f26d96585bde...fad43095d2665a0b37f9a5a4826016d15c3ef15c
You're receiving this email because of your account on gitlab.com.


_______________________________________________
Mailman-checkins mailing list -- mailman-checkins@python.org
To unsubscribe send an email to mailman-checkins-le...@python.org
https://mail.python.org/mailman3/lists/mailman-checkins.python.org/
Member address: arch...@jab.org

Reply via email to