Merge lp:~milo/linaro-patchmetrics/cached-user-check into lp:linaro-patchmetrics

Proposed by Milo Casagrande
Status: Merged
Merged at revision: 402
Proposed branch: lp:~milo/linaro-patchmetrics/cached-user-check
Merge into: lp:linaro-patchmetrics
Diff against target: 63 lines (+25/-3)
2 files modified
apps/patchwork/utils.py (+23/-3)
apps/settings.py (+2/-0)
To merge this branch: bzr merge lp:~milo/linaro-patchmetrics/cached-user-check
Reviewer Review Type Date Requested Status
Linaro Automation & Validation Pending
Review via email: mp+197944@code.launchpad.net

Description of the change

MP adds expiry check for cached users in the DB. Default value is set to 30 days.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'apps/patchwork/utils.py'
--- apps/patchwork/utils.py 2013-10-16 13:25:16 +0000
+++ apps/patchwork/utils.py 2013-12-05 18:34:32 +0000
@@ -50,6 +50,9 @@
50DEVNULL = open(os.devnull, "w")50DEVNULL = open(os.devnull, "w")
51atexit.register(close_fo, DEVNULL)51atexit.register(close_fo, DEVNULL)
5252
53# Default date format.
54DATE_FORMAT = '%Y-%m-%d %H:%M:%S.%f'
55
5356
54class GitException(Exception):57class GitException(Exception):
55 """General class for git exceptions."""58 """General class for git exceptions."""
@@ -501,9 +504,7 @@
501504
502 is_valid = False505 is_valid = False
503 if cached_user:506 if cached_user:
504 # TODO: we need to set a timeout and check again even if the user507 is_valid |= check_cached_user_validity(cached_user, db, crowd)
505 # is cached, it might have been removed from Crowd.
506 is_valid |= cached_user[1]
507 else:508 else:
508 # XXX: The first time this runs, it might hit the Crowd server hard,509 # XXX: The first time this runs, it might hit the Crowd server hard,
509 # since none of the users will be cached.510 # since none of the users will be cached.
@@ -514,6 +515,25 @@
514 return is_valid515 return is_valid
515516
516517
518def check_cached_user_validity(cached_user, db, crowd):
519 """Checks the user timestamp, and in case re-checks user validity.
520
521 :param chached_user: The user from the local cache.
522 :param db: A PatchworkDB instance for the cache backend.
523 :param crowd: A Crowd instance to update user data if necessary.
524 """
525 date_inserted = datetime.datetime.strptime(cached_user[2], DATE_FORMAT)
526 today = datetime.datetime.now()
527 delta = today - date_inserted
528
529 valid_user = cached_user[1]
530 if delta.days >= settings.CROWD_USERS_DB_EXPIRY:
531 valid_user = crowd.is_valid_user(cached_user[0])
532 db.update_user(cached_user[0], valid_user, today)
533
534 return valid_user
535
536
517def get_patches_matching_commit(project, commit_diff, commit_msg,537def get_patches_matching_commit(project, commit_diff, commit_msg,
518 commit_author):538 commit_author):
519 """Return the Patch objects that are likely matches to the given commit.539 """Return the Patch objects that are likely matches to the given commit.
520540
=== modified file 'apps/settings.py'
--- apps/settings.py 2013-12-03 09:38:31 +0000
+++ apps/settings.py 2013-12-05 18:34:32 +0000
@@ -150,6 +150,8 @@
150# Full path to a DB file.150# Full path to a DB file.
151# This is used to have a cache of which users exists in the Crowd database.151# This is used to have a cache of which users exists in the Crowd database.
152CROWD_USERS_DB_FILE = None152CROWD_USERS_DB_FILE = None
153# Number of days before checking again if a user exists in the Crowd db.
154CROWD_USERS_DB_EXPIRY = 30
153155
154# Where to store the git repos that we scan to identify which patches have156# Where to store the git repos that we scan to identify which patches have
155# been committed.157# been committed.

Subscribers

People subscribed via source and target branches