def getFast(self, attrib, accuracy=1.0): # self.__getattr__ is wrapped and calls getFast(). # Thus, access self.__dict__ directly. # First, check local self.__dict__ cache. if accuracy <= self.LocalAttribAccuracy and attrib in self.__dict__: return self.__dict__[attrib], self.LocalAttribAccuracy # Now try the DB. import songdb expectedType = getattr(songdb.Attribs.get(attrib, None), "type", None) if attrib in songdb.Attribs and self._useDb and self.id: try: value = songdb.getSongAttrib(self, attrib) value = utils.fixValue(value, expectedType) except AttributeError: pass else: # Cache it locally. object.__setattr__(self, attrib, value) # We expect perfect accuracy if we have it in the DB. return value, 1 # All has failed so far. Try the estimate function. estimateFunc = getattr(self, "_estimate_" + attrib, None) if estimateFunc: value, estAccuracy = estimateFunc() value = utils.fixValue(value, expectedType) if estAccuracy == 1: # save locally and in DB setattr(self, attrib, value) if estAccuracy >= accuracy: return value, estAccuracy return None, 0
def getFast(self, attrib, accuracy=1): # self.__getattr__ is wrapped and calls getFast(). # Thus, access self.__dict__ directly. # First, check local self.__dict__ cache. if accuracy <= self.LocalAttribAccuracy and attrib in self.__dict__: return self.__dict__[attrib], self.LocalAttribAccuracy # Now try the DB. import songdb expectedType = getattr(songdb.Attribs.get(attrib, None), "type", None) if attrib in songdb.Attribs and self._useDb and self.id: try: value = songdb.getSongAttrib(self, attrib) value = utils.fixValue(value, expectedType) except AttributeError: pass else: # Cache it locally. object.__setattr__(self, attrib, value) # We expect perfect accuracy if we have it in the DB. return value, 1 # All has failed so far. Try the estimate function. estimateFunc = getattr(self, "_estimate_" + attrib, None) if estimateFunc: value, estAccuracy = estimateFunc() value = utils.fixValue(value, expectedType) if estAccuracy == 1: # save locally and in DB setattr(self, attrib, value) if estAccuracy >= accuracy: return value, estAccuracy return None, 0