Changeset 3724 for framework

Show
Ignore:
Timestamp:
01/19/11 11:09:43 (16 months ago)
Author:
elemoine
Message:

improve bulk inserts performance, thanks Jorge Gustavo Rocha for reporting the issue, r=bbinet (closes #612)

Location:
framework/server/trunk/mapfish
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • framework/server/trunk/mapfish/protocol.py

    r3715 r3724  
    307307                self.Session.add(obj) 
    308308            objects.append(obj) 
     309        # We call flush, create the feature collection, and then commit. Commit 
     310        # expires the session, so we create the feature collection before 
     311        # commit to avoid SELECT queries in toFeature. 
     312        if execute: 
     313            self.Session.flush() 
     314        collection = None 
     315        if len(objects) > 0: 
     316            collection = FeatureCollection([o.toFeature() for o in objects]) 
    309317        if execute: 
    310318            self.Session.commit() 
    311319        response.status = 201 
    312         if len(objects) > 0: 
    313             features = [o.toFeature() for o in objects] 
    314             return FeatureCollection(features) 
    315         return 
     320        return collection 
    316321 
    317322    def update(self, request, response, id): 
     
    331336            self.before_update(request, feature, obj) 
    332337        self.__copy_attributes(feature, obj) 
     338        # We call flush, create the feature, and then commit. Commit expires 
     339        # the session, so we create the feature before commit to avoid SELECT 
     340        # queries in toFeature. 
     341        self.Session.flush() 
     342        feature = obj.toFeature() 
    333343        self.Session.commit() 
    334344        response.status = 201 
    335         return obj.toFeature() 
     345        return feature 
    336346 
    337347    def delete(self, request, response, id): 
     
    352362        """Updates the passed-in object with the values 
    353363        from the GeoJSON feature.""" 
    354         # create a Shapely geometry from GeoJSON and persist the geometry using WKB 
     364        # create a Shapely geometry from GeoJSON and persist the geometry 
     365        # using WKB 
    355366        shape = asShape(json_feature.geometry) 
    356367        srid = self.mapped_class.geometry_column().type.srid 
    357368        obj.geometry = WKBSpatialElement(buffer(shape.wkb), srid=srid) 
    358         # also store the Shapely geometry so that we can use it to return the geometry as GeoJSON 
    359         obj.geometry.shape = shape 
     369        # also store the Shapely geometry so that we can use it to return the 
     370        # geometry as GeoJSON and avoid a SELECT 
     371        obj._mf_shape = shape 
    360372        for key in json_feature.properties: 
    361373            obj[key] = json_feature.properties[key] 
  • framework/server/trunk/mapfish/sqlalchemygeom.py

    r3715 r3724  
    209209                attributes[k] = getattr(self, k) 
    210210         
    211         if hasattr(self.geometry, 'shape') and self.geometry.shape is not None: 
     211        if hasattr(self, '_mf_shape') and self._mf_shape is not None: 
    212212            # we already have the geometry as Shapely geometry (when updating/inserting) 
    213             geometry = self.geometry.shape 
     213            geometry = self._mf_shape 
    214214        elif hasattr(self.geometry, 'geom_wkb') and self.geometry.geom_wkb is not None: 
    215215            # create a Shapely geometry from the WKB geometry returned from the database 
  • framework/server/trunk/mapfish/tests/test_oracle.py

    r3715 r3724  
    5858 
    5959#engine = create_engine('oracle://gis:gis@localhost:1521/gis', echo=True) 
    60 engine = create_engine('oracle://system:system@172.16.103.134:1521/gis', echo=True) 
     60engine = create_engine('oracle://system:system@172.16.103.136:1521/gis', echo=True) 
    6161 
    6262metadata = MetaData(engine) 
  • framework/server/trunk/mapfish/tests/test_protocol.py

    r3659 r3724  
    330330        for obj in Session.new: 
    331331            assert obj["text"] == "foo" 
    332             assert obj.geometry.shape.x == 45 
    333             assert obj.geometry.shape.y == 5 
     332            assert obj._mf_shape.x == 45 
     333            assert obj._mf_shape.y == 5 
    334334        Session.rollback()