From: Martin d'A. <Mar...@s2...> - 2004-12-02 22:13:29
|
> 1. caching of newly created objects (inserts) > 2. Avoid issuing the subseqent select to initialize newly created > objects (_init() calls selectOne()) > > Ryan Harper The purpose of SQLObject._init() seems to be the initialization of the instance member values. To do that, it needs to fetch the data from the database. But since this is called on object creation, the data should be known without going to the database. Martin |
From: Martin d'A. <Mar...@s2...> - 2004-12-02 23:06:50
|
> > 1. caching of newly created objects (inserts) > > 2. Avoid issuing the subseqent select to initialize newly created > > objects (_init() calls selectOne()) > > > > Ryan Harper > > The purpose of SQLObject._init() seems to be the initialization of the > instance member values. To do that, it needs to fetch the data from the > database. But since this is called on object creation, the data should be > known without going to the database. > > Martin I have two solutions for this problem. 1) put an if around the whole tail end of SQLObject._init() and do not call self._SO_selectInit(selectResults) 2) if around the line: selectResults = self._connection._SO_selectOne(self, dbNames) and fill in the selectResults tuple from within the SQLObject.self (with getattr(self,dbName)) and still call self._SO_selectInit(selectResults) Is one solution preferable over the other? Should I set self.dirty = True? Thanks, Martin |
From: Ryan H. <rh...@sh...> - 2004-12-02 23:16:27
|
* Martin d'Anjou <Mar...@s2...> [2004-12-02 16:14]: > > 2. Avoid issuing the subseqent select to initialize newly created > > objects (_init() calls selectOne()) > > > > Ryan Harper > > The purpose of SQLObject._init() seems to be the initialization of the > instance member values. To do that, it needs to fetch the data from the > database. But since this is called on object creation, the data should be > known without going to the database. > I don't mind this being done. It is a clean design to initialize the members from the results of the insert. I don't want that changed, rather I want something like: Person(name="Bob",__cache=False,__initObject=False) The above telling SQLObject to not add a ref to the connection._cache and to not bother running _init(). Ryan Harper |
From: Ryan H. <rh...@sh...> - 2004-12-02 23:25:42
|
> selectResults = self._connection._SO_selectOne(self, dbNames) > > and fill in the selectResults tuple from within the SQLObject.self (with > getattr(self,dbName)) and still call self._SO_selectInit(selectResults) > > Is one solution preferable over the other? Should I set self.dirty = True? It seems to me the best way to preserve SQLObject behavior without introducing a new toggle ( as I previously suggested ) would be to (as you suggest) fill out selectResults without issuing a select to the database. Unless someone sees a reason why SQLObject SHOULD or MUST query the database rather than using the values that were passed to the table I think that would be a good optimization with no interface impact. Ryan Harper |
From: Justin A. <JA...@ua...> - 2004-12-02 23:32:04
|
On Thu, 2004-12-02 at 18:25, Ryan Harper wrote: > It seems to me the best way to preserve SQLObject behavior without > introducing a new toggle ( as I previously suggested ) would be to (as > you suggest) fill out selectResults without issuing a select to > the database. > > Unless someone sees a reason why SQLObject SHOULD or MUST query the > database rather than using the values that were passed to the table I > think that would be a good optimization with no interface impact. > > Ryan Harper There is the previous mentioned case of using sqlbuilder.func.NOW() and others... Other than that I would certainly welcome the speed boost that this would give :-) -- -- Justin Azoff -- Network Performance Analyst |
From: Martin d'A. <Mar...@s2...> - 2004-12-02 23:43:42
|
On Thu, 2 Dec 2004, Justin Azoff wrote: > On Thu, 2004-12-02 at 18:25, Ryan Harper wrote: > > It seems to me the best way to preserve SQLObject behavior without > > introducing a new toggle ( as I previously suggested ) would be to (as > > you suggest) fill out selectResults without issuing a select to > > the database. > > > > Unless someone sees a reason why SQLObject SHOULD or MUST query the > > database rather than using the values that were passed to the table I > > think that would be a good optimization with no interface impact. > > > > Ryan Harper I can see one reason, but I am not sure it is true: what if you need to immediately use an auto_increment value in a subsequent insert for a one/many-to-many relationship? Martin |
From: Martin d'A. <Mar...@s2...> - 2004-12-03 00:51:59
|
> > selectResults = self._connection._SO_selectOne(self, dbNames) > > > > and fill in the selectResults tuple from within the SQLObject.self (with > > getattr(self,dbName)) and still call self._SO_selectInit(selectResults) > > > > Is one solution preferable over the other? Should I set self.dirty = True? > > It seems to me the best way to preserve SQLObject behavior without > introducing a new toggle ( as I previously suggested ) would be to (as > you suggest) fill out selectResults without issuing a select to > the database. I don't know how to do it without a new toggle. I have something here but is it not working yet. Admire a modified section of main.py: if not selectResults: if (self._fetchValuesOnCreate): dbNames = [col.dbName for col in self._SO_columns] selectResults = self._connection._SO_selectOne(self, dbNames) else: names = [col.name for col in self._SO_columns] tmp_selectResults = [] for name in names: tmp_selectResults.append(getattr(self,name)) selectResults = tuple(tmp_selectResults) if not selectResults: raise SQLObjectNotFound, "The object %s by the ID %s does not exist" % (self.__class__.__name__, self.id) self._SO_selectInit(selectResults) self._SO_createValues = {} self.dirty = False The problem is with "tmp_selectResults.append(getattr(self,name))". self is some sort of object that overloads getattr to go to the database to get the attribute value!!! Martin |