Skip to content

Commit

Permalink
[afs] Don't request intersecting features from server if all
Browse files Browse the repository at this point in the history
features are already locally cached
  • Loading branch information
nyalldawson committed Feb 20, 2018
1 parent a818953 commit c0d4ce7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/providers/arcgisrest/qgsafsfeatureiterator.cpp
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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() )
Expand Down Expand Up @@ -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 );
Expand Down
5 changes: 5 additions & 0 deletions src/providers/arcgisrest/qgsafsshareddata.cpp
Expand Up @@ -161,3 +161,8 @@ QgsFeatureIds QgsAfsSharedData::getFeatureIdsInExtent( const QgsRectangle &exten
}
return ids;
}

bool QgsAfsSharedData::hasCachedAllFeatures() const
{
return mCache.count() == mObjectIds.count();
}
2 changes: 2 additions & 0 deletions src/providers/arcgisrest/qgsafsshareddata.h
Expand Up @@ -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;
Expand Down

0 comments on commit c0d4ce7

Please sign in to comment.