summaryrefslogtreecommitdiffstats
path: root/devel
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-11-15 22:04:33 +0100
committerDan McGee <dan@archlinux.org>2011-11-15 22:04:33 +0100
commit0344f8ad564644c50203985255fab1d053aed463 (patch)
tree9029728a3c96cbf1d6d8ce31edd6f1b5967a9b01 /devel
parent84679f90a772e591dae2dea28194730d5453e6cf (diff)
downloadarchweb-0344f8ad564644c50203985255fab1d053aed463.tar.gz
archweb-0344f8ad564644c50203985255fab1d053aed463.tar.xz
Add ability to cache users by username on the UserFinder
This is very useful in the signoff message population script where we are very likely to encounter the same users over and over. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'devel')
-rw-r--r--devel/utils.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/devel/utils.py b/devel/utils.py
index d7a154a..62b12cd 100644
--- a/devel/utils.py
+++ b/devel/utils.py
@@ -47,6 +47,7 @@ SELECT pr.user_id, COUNT(*), COUNT(p.flag_date)
class UserFinder(object):
def __init__(self):
self.cache = {}
+ self.username_cache = {}
@staticmethod
def user_email(name, email):
@@ -111,7 +112,22 @@ class UserFinder(object):
self.cache[userstring] = user
return user
+ def find_by_username(self, username):
+ if not username:
+ return None
+ if username in self.username_cache:
+ return self.username_cache[username]
+
+ try:
+ user = User.objects.get(username=username)
+ except User.DoesNotExist:
+ user = None
+
+ self.username_cache[username] = user
+ return user
+
def clear_cache(self):
self.cache = {}
+ self.username_cache = {}
# vim: set ts=4 sw=4 et: