Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release-3_34] [afs] Clone shared data before setting filters #56221

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/providers/arcgisrest/qgsafsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,11 @@ bool QgsAfsProvider::setSubsetString( const QString &subset, bool )
if ( trimmedSubset == mSharedData->subsetString() )
return true;

// We must not change the subset string of the shared data used in another iterator/data provider,
// or other layers attached to the same shared data (i.e. layers with a data provider cloned from
// this one) will also unwantedly inherit the new subset string.
mSharedData = mSharedData->clone();

mSharedData->setSubsetString( trimmedSubset );

// Update datasource uri too
Expand Down
19 changes: 19 additions & 0 deletions src/providers/arcgisrest/qgsafsshareddata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ QgsAfsSharedData::QgsAfsSharedData( const QgsDataSourceUri &uri )
{
}

std::shared_ptr< QgsAfsSharedData > QgsAfsSharedData::clone() const
{
QgsReadWriteLocker locker( mReadWriteLock, QgsReadWriteLocker::Read );
std::shared_ptr< QgsAfsSharedData > copy = std::make_shared< QgsAfsSharedData >( mDataSource );
copy->mLimitBBox = mLimitBBox;
copy->mExtent = mExtent;
copy->mGeometryType = mGeometryType;
copy->mFields = mFields;
copy->mMaximumFetchObjectsCount = mMaximumFetchObjectsCount;
copy->mObjectIdFieldName = mObjectIdFieldName;
copy->mObjectIdFieldIdx = mObjectIdFieldIdx;
copy->mObjectIds = mObjectIds;
copy->mObjectIdToFeatureId = mObjectIdToFeatureId;
copy->mDeletedFeatureIds = mDeletedFeatureIds;
copy->mCache = mCache;
copy->mSourceCRS = mSourceCRS;
return copy;
}

QString QgsAfsSharedData::subsetString() const
{
return mDataSource.sql();
Expand Down
3 changes: 3 additions & 0 deletions src/providers/arcgisrest/qgsafsshareddata.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class QgsAfsSharedData
public:
QgsAfsSharedData( const QgsDataSourceUri &uri );

//! Creates a deep copy of this shared data
std::shared_ptr< QgsAfsSharedData > clone() const;

long long objectIdCount() const;
long long featureCount() const;
bool isDeleted( QgsFeatureId id ) const { return mDeletedFeatureIds.contains( id ); }
Expand Down
Loading