Chromium Code Reviews| Index: rietveld.py |
| diff --git a/rietveld.py b/rietveld.py |
| index d4ac39bab08060ea3c6414d3b9ad32b986d266f0..5d81e7396e4016831b330923a53994de67d060cf 100644 |
| --- a/rietveld.py |
| +++ b/rietveld.py |
| @@ -14,6 +14,7 @@ The following hypothesis are made: |
| - A patch set cannot be modified |
| """ |
| +import copy |
| import json |
| import logging |
| import re |
| @@ -395,3 +396,41 @@ class Rietveld(object): |
| # DEPRECATED. |
| Send = get |
| + |
| + |
| +class CachingRietveld(Rietveld): |
| + """Caches the common queries. |
| + |
| + Not to be used in long-standing processes, like the commit queue. |
| + """ |
| + def __init__(self, *args, **kwargs): |
| + super(CachingRietveld, self).__init__(*args, **kwargs) |
| + self._cache = {} |
| + |
| + def _lookup(self, function_name, args, update): |
| + """Caches the return values corresponding to the arguments. |
| + |
| + It is important that the arguments are standardized, like None vs False. |
| + """ |
| + function_cache = self._cache.setdefault(function_name, {}) |
| + if args not in function_cache: |
| + function_cache[args] = update(*args) |
| + return copy.deepcopy(function_cache[args]) |
| + |
| + def get_description(self, issue): |
| + return self._lookup( |
| + 'get_description', |
| + (issue,), |
| + super(CachingRietveld, self).get_description) |
| + |
| + def get_issue_properties(self, issue, messages): |
|
Isaac (away)
2012/11/26 05:12:39
get_issue_properties(<issue>, True) returns a supe
M-A Ruel
2012/11/27 20:15:06
Done
|
| + return self._lookup( |
| + 'get_issue_properties', |
| + (issue, bool(messages)), |
| + super(CachingRietveld, self).get_issue_properties) |
| + |
| + def get_patchset_properties(self, issue, patchset): |
| + return self._lookup( |
| + 'get_patchset_properties', |
| + (issue, patchset), |
| + super(CachingRietveld, self).get_patchset_properties) |