[Modeling-cvs] SF.net SVN: modeling: [999] trunk/ProjectModeling
Status: Abandoned
Brought to you by:
sbigaret
From: <sbi...@us...> - 2006-04-22 18:47:15
|
Revision: 999 Author: sbigaret Date: 2006-04-22 11:47:08 -0700 (Sat, 22 Apr 2006) ViewCVS: http://svn.sourceforge.net/modeling/?rev=999&view=rev Log Message: ----------- Fixed bug #1474720: when saving changes, the PKs needed for the inserted objects were retrieved one after the other, opening and closing a transaction for every PK Modified Paths: -------------- trunk/ProjectModeling/CHANGES trunk/ProjectModeling/Modeling/DatabaseContext.py Modified: trunk/ProjectModeling/CHANGES =================================================================== --- trunk/ProjectModeling/CHANGES 2006-04-22 18:36:10 UTC (rev 998) +++ trunk/ProjectModeling/CHANGES 2006-04-22 18:47:08 UTC (rev 999) @@ -7,6 +7,12 @@ ** Distributed under a 3-clause BSD-style license, see LICENSE for details ** ----------------------------------------------------------------------------- + * Fixed bug #1474720: when saving changes, the PKs needed for the inserted + objects are retrieved one after the other, opening and closing a + transaction for every PK. PKs are now fetched by batch, in a single + transaction for all objects having the same entity. + This should make inserting a lot of objects really faster. + * Feature request #1011515: Configurability of ABORT/COMMIT on read-only transactions (for postgresql). Modified: trunk/ProjectModeling/Modeling/DatabaseContext.py =================================================================== --- trunk/ProjectModeling/Modeling/DatabaseContext.py 2006-04-22 18:36:10 UTC (rev 998) +++ trunk/ProjectModeling/Modeling/DatabaseContext.py 2006-04-22 18:47:08 UTC (rev 999) @@ -1066,18 +1066,23 @@ # get the primary keys for inserted objects - # this could be made more efficient if PKs were asked within a single - # round-trip to the DB + # 1st: sort the inserted objects by entity + # 2nd: fetch the primary keys, one entity after the other + # The purpose is to make one and only one round-trip to the db + # (==one transaction) per entity self.lock() try: channel=self.availableChannel().adaptorChannel() + entity_to_gids={} for gID in self._inserted_gIDs: - entity=ec.objectForGlobalID(gID).classDescription().entity() - pk=channel.primaryKeysForNewRowsWithEntity(1, entity) - self._pks_for_inserted_gIDs[gID]=pk[0] - - newGid=KeyGlobalID(entity.name(), self._pks_for_inserted_gIDs[gID]) - self.__temporaryGID_to_KeyGlobalID[gID]=newGid + entity_to_gids.setdefault(ec.objectForGlobalID(gID).classDescription().entity(), []).append(gID) + + for entity, gIDs in entity_to_gids.items(): + pks=channel.primaryKeysForNewRowsWithEntity(len(gIDs), entity) + for gID, pk in map(None, gIDs, pks): + self._pks_for_inserted_gIDs[gID]=pk + newGid=KeyGlobalID(entity.name(), self._pks_for_inserted_gIDs[gID]) + self.__temporaryGID_to_KeyGlobalID[gID]=newGid finally: self.unlock() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |