From: Oleg B. <ph...@ph...> - 2009-02-03 20:45:43
|
On Tue, Feb 03, 2009 at 02:37:16PM -0500, Stef Telford wrote: > Oleg Broytmann wrote: > > Because SQLObject needs to generate unique alias names and a global > > counter is the simplest way to do it. Think about joining a table > > with itself - you need two different names for the table. > > Sorry, perhaps I am being stupid here (always a possability) but, how > many self joins are we expecting in a query ? I mean to say, isn't > saying 'selfName = self.__class__.__name__ + "_%d" % int(random())' > good enough ? Are you sure calling random() and int() is really so much faster than lock/increase counter/unlock? Are you sure you are optimizing a real stumbling block? > it seems crazy to call _setattr_ if the row has been grabbed from the > cache (as any call to setattr would/should invalidate the object in > the cache and force a reload from the database). What __setattr__ do you mean? SQLObject doesn't have __setattr__, so it doesn't invalidate object, and certainly doesn't reload it from DB. > Think of 'completeName' .. which is simply self.firstName + " " + > self.lastName. I can think of a 'good reason' to only call -that- > after the initial object has been created (I know that this should be > a model function which jst returns the firstName + " " + lastName but, > go with me here, I am trying to keep my example simple). > > If there is a 'newRowInDB' flag, then I can say something like; > > def _init(self, id, connection=None, selectResults=None): ''' > > Overload this method if you need to do anything special ''' > > SQLObject._init(self, id, connection, selectResults) if > > self.newRowInDB: self.completeName = self.firstName + " " + > > self.lastName memcache.put("%s_%s" % (self.__class__.__name__, > > self.id)) ._SO_finishCreate() and ._init() are only called on create (INSERT) and not called when the object is fetched from the cache so you don't need a flag here - just set self.completeName in your overridden _init(). Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |