Avoid redundant polling of DB for metadata

Every time self.metadata is read, it triggers a refresh from the database.
We were accessing it multiple times in a loop, which is not only wasteful
but can get very O(n^2) for a WaitCondition with a high Count.

Partial-Bug: #1306743

Change-Id: I1a82afac6c4ef56dbf87722648034c05abef4010
This commit is contained in:
Zane Bitter 2014-04-17 18:42:03 -04:00
parent beb76daf44
commit 0114afcf56
1 changed files with 4 additions and 5 deletions

View File

@ -91,8 +91,7 @@ class WaitConditionHandle(signal_responder.SignalResponder):
'''
Return a list of the Status values for the handle signals
'''
return [self.metadata[s]['Status']
for s in self.metadata]
return [v['Status'] for v in self.metadata.values()]
def get_status_reason(self, status):
'''
@ -100,9 +99,9 @@ class WaitConditionHandle(signal_responder.SignalResponder):
If there is more than one handle signal matching the specified status
then return a semicolon delimited string containing all reasons
'''
return ';'.join([self.metadata[s]['Reason']
for s in self.metadata
if self.metadata[s]['Status'] == status])
return ';'.join([v['Reason']
for v in self.metadata.values()
if v['Status'] == status])
WAIT_STATUSES = (