Skip to content
Permalink
Browse files

[afs] Don't request intersecting features from server if all

features are already locally cached
  • Loading branch information
nyalldawson committed Feb 20, 2018
1 parent a818953 commit c0d4ce70f257ba54e054e47dafc7e7a6d26517d0
@@ -71,12 +71,15 @@ QgsAfsFeatureIterator::QgsAfsFeatureIterator( QgsAfsFeatureSource *source, bool
requestIds.insert( mRequest.filterFid() );
}

if ( !mFilterRect.isNull() )
if ( !mFilterRect.isNull() && !mSource->sharedData()->hasCachedAllFeatures() )
{
// defer request to find features in filter rect until first feature is requested
// this allows time for a interruption checker to be installed on the iterator
// and avoids performing this expensive check in the main thread when just
// preparing iterators

// (but if we've already cached ALL the features, we skip this -- there's no need for
// firing off another request to the server)
mDeferredFeaturesInFilterRectCheck = true;
}

@@ -129,6 +132,10 @@ bool QgsAfsFeatureIterator::fetchFeature( QgsFeature &f )
mFeatureIterator = mRemainingFeatureIds.at( 0 );

mDeferredFeaturesInFilterRectCheck = false;

// discard the filter rect - we know that the features in mRemainingFeatureIds are gauranteed
// to be intersecting the rect, so avoid any extra unnecessary checks
mFilterRect = QgsRectangle();
}

if ( !mFeatureIdList.empty() && mRemainingFeatureIds.empty() )
@@ -171,6 +178,10 @@ bool QgsAfsFeatureIterator::fetchFeature( QgsFeature &f )
{
++mFeatureIterator;
}

if ( !mFilterRect.isNull() && ( !f.hasGeometry() || !f.geometry().intersects( mFilterRect ) ) )
success = false;

if ( !success )
continue;
geometryToDestinationCrs( f, mTransform );
@@ -161,3 +161,8 @@ QgsFeatureIds QgsAfsSharedData::getFeatureIdsInExtent( const QgsRectangle &exten
}
return ids;
}

bool QgsAfsSharedData::hasCachedAllFeatures() const
{
return mCache.count() == mObjectIds.count();
}
@@ -41,6 +41,8 @@ class QgsAfsSharedData : public QObject
bool getFeature( QgsFeatureId id, QgsFeature &f, const QgsRectangle &filterRect = QgsRectangle(), QgsFeedback *feedback = nullptr );
QgsFeatureIds getFeatureIdsInExtent( const QgsRectangle &extent, QgsFeedback *feedback );

bool hasCachedAllFeatures() const;

private:
friend class QgsAfsProvider;
QMutex mMutex;

0 comments on commit c0d4ce7

Please sign in to comment.
You can’t perform that action at this time.