Skip to content

Commit c0d4ce7

Browse files
committedFeb 20, 2018
[afs] Don't request intersecting features from server if all
features are already locally cached
1 parent a818953 commit c0d4ce7

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed
 

‎src/providers/arcgisrest/qgsafsfeatureiterator.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,15 @@ QgsAfsFeatureIterator::QgsAfsFeatureIterator( QgsAfsFeatureSource *source, bool
7171
requestIds.insert( mRequest.filterFid() );
7272
}
7373

74-
if ( !mFilterRect.isNull() )
74+
if ( !mFilterRect.isNull() && !mSource->sharedData()->hasCachedAllFeatures() )
7575
{
7676
// defer request to find features in filter rect until first feature is requested
7777
// this allows time for a interruption checker to be installed on the iterator
7878
// and avoids performing this expensive check in the main thread when just
7979
// preparing iterators
80+
81+
// (but if we've already cached ALL the features, we skip this -- there's no need for
82+
// firing off another request to the server)
8083
mDeferredFeaturesInFilterRectCheck = true;
8184
}
8285

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

131134
mDeferredFeaturesInFilterRectCheck = false;
135+
136+
// discard the filter rect - we know that the features in mRemainingFeatureIds are gauranteed
137+
// to be intersecting the rect, so avoid any extra unnecessary checks
138+
mFilterRect = QgsRectangle();
132139
}
133140

134141
if ( !mFeatureIdList.empty() && mRemainingFeatureIds.empty() )
@@ -171,6 +178,10 @@ bool QgsAfsFeatureIterator::fetchFeature( QgsFeature &f )
171178
{
172179
++mFeatureIterator;
173180
}
181+
182+
if ( !mFilterRect.isNull() && ( !f.hasGeometry() || !f.geometry().intersects( mFilterRect ) ) )
183+
success = false;
184+
174185
if ( !success )
175186
continue;
176187
geometryToDestinationCrs( f, mTransform );

‎src/providers/arcgisrest/qgsafsshareddata.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,8 @@ QgsFeatureIds QgsAfsSharedData::getFeatureIdsInExtent( const QgsRectangle &exten
161161
}
162162
return ids;
163163
}
164+
165+
bool QgsAfsSharedData::hasCachedAllFeatures() const
166+
{
167+
return mCache.count() == mObjectIds.count();
168+
}

‎src/providers/arcgisrest/qgsafsshareddata.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class QgsAfsSharedData : public QObject
4141
bool getFeature( QgsFeatureId id, QgsFeature &f, const QgsRectangle &filterRect = QgsRectangle(), QgsFeedback *feedback = nullptr );
4242
QgsFeatureIds getFeatureIdsInExtent( const QgsRectangle &extent, QgsFeedback *feedback );
4343

44+
bool hasCachedAllFeatures() const;
45+
4446
private:
4547
friend class QgsAfsProvider;
4648
QMutex mMutex;

0 commit comments

Comments
 (0)
Please sign in to comment.