diff options
author | Owen W. Taylor <otaylor@fishsoup.net> | 2009-08-31 01:06:21 -0400 |
---|---|---|
committer | Owen W. Taylor <otaylor@fishsoup.net> | 2009-08-31 01:07:16 -0400 |
commit | 7106719039cf7223faa22571fd8e5b7595664abb (patch) | |
tree | a025c2154e258ecd3ea1060bc30fef4f7f714b83 | |
parent | 9b8a0acd33c457111e2b07076f6b30600ad6b5a1 (diff) | |
download | git-bz-7106719039cf7223faa22571fd8e5b7595664abb.tar.gz |
Cache legal field values
Use our constant-field-value cache to cache legal field values
for each server; this cuts round trips for 'git bz edit' from
3 to 1, which is quite noticeably faster.
The legal_values method is moved from Bug to BugServer, where
it makes more sense.
-rwxr-xr-x | git-bz | 47 |
1 files changed, 28 insertions, 19 deletions
@@ -893,6 +893,32 @@ class BugServer(object): return self._xmlrpc_proxy + # Query the server for the legal values of the given field; returns an + # array, or None if the query failed + def _legal_values(self, field): + try: + response = self.get_xmlrpc_proxy().Bug.legal_values({ 'field': field }) + cache.set(self.host, 'legal_' + field, response['values']) + return response['values'] + except xmlrpclib.Fault, e: + if e.faultCode == -32000: # https://bugzilla.mozilla.org/show_bug.cgi?id=513511 + return None + raise + except xmlrpclib.ProtocolError, e: + if e.errcode == 500: # older bugzilla versions die this way + return None + elif e.errcode == 404: # really old bugzilla, no XML-RPC + return None + raise + + def legal_values(self, field): + try: + return cache.get(self.host, 'legal_' + field) + except IndexError: + values = self._legal_values(field) + cache.set(self.host, 'legal_' + field, values) + return values + class BugTransport(xmlrpclib.Transport): def __init__(self, server): xmlrpclib.Transport.__init__(self) @@ -1104,23 +1130,6 @@ class Bug(object): print "Attached %s" % filename - # Query the server for the legal values of the given field; returns an - # array, or None if the query failed - def legal_values(self, field): - try: - response = self.server.get_xmlrpc_proxy().Bug.legal_values({ 'field': field }) - return response['values'] - except xmlrpclib.Fault, e: - if e.faultCode == -32000: # https://bugzilla.mozilla.org/show_bug.cgi?id=513511 - return None - raise - except xmlrpclib.ProtocolError, e: - if e.errcode == 500: # older bugzilla versions die this way - return None - elif e.errcode == 404: # really old bugzilla, no XML-RPC - return None - raise - # Update specified fields of a bug; keyword arguments are interpreted # as field_name=value def update(self, **changes): @@ -1492,7 +1501,7 @@ def edit_bug(bug, applied_commits=None): template.write("# Uncommment and edit to change resolution\n") else: template.write("# Uncomment to resolve bug\n") - legal_resolutions = bug.legal_values('resolution') + legal_resolutions = bug.server.legal_values('resolution') if legal_resolutions: # Require non-empty resolution. DUPLICATE, MOVED would need special support legal_resolutions = [x for x in legal_resolutions if x not in ('', 'DUPLICATE', 'MOVED')] @@ -1507,7 +1516,7 @@ def edit_bug(bug, applied_commits=None): template.write("\n# Lines below change patch status, unless commented out\n") else: template.write("\n# To change patch status, uncomment below, edit 'committed' as appropriate.\n") - legal_statuses = bug.legal_values('attachments.status') + legal_statuses = bug.server.legal_values('attachments.status') if legal_statuses: legal_statuses.append('obsolete') template.write("# possible statuses: %s\n" % abbreviation_help_string(legal_statuses)) |