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

Load OGR layers in parallel when opening a project #58337

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 10 additions & 7 deletions src/core/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,14 +1018,17 @@ void QgsOgrProvider::loadMetadata()
{
QRecursiveMutex *mutex = nullptr;
OGRLayerH layer = mOgrOrigLayer->getHandleAndMutex( mutex );
QMutexLocker locker( mutex );

const QString identifier = GDALGetMetadataItem( layer, "IDENTIFIER", "" );
if ( !identifier.isEmpty() )
mLayerMetadata.setTitle( identifier ); // see geopackage specs -- "'identifier' is analogous to 'title'"
const QString abstract = GDALGetMetadataItem( layer, "DESCRIPTION", "" );
if ( !abstract.isEmpty() )
mLayerMetadata.setAbstract( abstract );
{
QMutexLocker locker( mutex );

const QString identifier = GDALGetMetadataItem( layer, "IDENTIFIER", "" );
if ( !identifier.isEmpty() )
mLayerMetadata.setTitle( identifier ); // see geopackage specs -- "'identifier' is analogous to 'title'"
const QString abstract = GDALGetMetadataItem( layer, "DESCRIPTION", "" );
if ( !abstract.isEmpty() )
mLayerMetadata.setAbstract( abstract );
}

if ( mGDALDriverName == QLatin1String( "GPKG" ) )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/providers/ogr/qgsogrprovidermetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ void QgsOgrProviderMetadata::saveConnection( const QgsAbstractProviderConnection

QgsProviderMetadata::ProviderCapabilities QgsOgrProviderMetadata::providerCapabilities() const
{
return FileBasedUris | SaveLayerMetadata;
return FileBasedUris | SaveLayerMetadata | ParallelCreateProvider;
}

///@endcond
23 changes: 19 additions & 4 deletions src/core/providers/ogr/qgsogrproviderutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2253,7 +2253,11 @@ QgsOgrProviderUtils::DatasetWithLayers *QgsOgrProviderUtils::createDatasetWithLa
errCause = QObject::tr( "Cannot open %1." ).arg( dsName );
return nullptr;
}
( *sMapDSNameToLastModifiedDate() )[dsName] = getLastModified( dsName );

{
QMutexLocker locker( sGlobalMutex() );
( *sMapDSNameToLastModifiedDate() )[dsName] = getLastModified( dsName );
}

OGRLayerH hLayer = GDALDatasetGetLayerByName(
hDS, layerName.toUtf8().constData() );
Expand Down Expand Up @@ -2354,15 +2358,26 @@ QgsOgrLayerUniquePtr QgsOgrProviderUtils::getLayer( const QString &dsName,
return layer;
}

// It can take a while to open a dataset (especially if it is from a remote source),
// so let's unlock the mutex while opening, so that we can create datasets from other
// threads as well.
locker.unlock();

QgsOgrLayerUniquePtr layer;
QgsOgrProviderUtils::DatasetWithLayers *ds =
createDatasetWithLayers( dsName, updateMode, options, layerName, ident, layer, errCause );
if ( !ds )
return nullptr;

QList<DatasetWithLayers *> datasetList;
datasetList.push_back( ds );
sMapSharedDS[ident] = datasetList;
locker.relock();

// In theory it could have happened that some other thread has opened this dataset
// at the same time as we did, let's only add a new entry to sMapSharedDS if there's none
if ( !sMapSharedDS.contains( ident ) )
{
sMapSharedDS[ident] = QList<DatasetWithLayers *>();
}
sMapSharedDS[ident].push_back( ds );

return layer;
}
Expand Down
Loading