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/ p...@phd.pp.ru Programmers don't die, they just GOSUB without RETURN. ------------------------------------------------------------------------------ Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) software. With Adobe AIR, Ajax developers can use existing skills and code to build responsive, highly engaging applications that combine the power of local resources and data with the reach of the web. Download the Adobe AIR SDK and Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com _______________________________________________ sqlobject-discuss mailing list sqlobject-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss