-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Trust layer metadata propagation #38464
Conversation
debeb68
to
4b9f36d
Compare
src/core/qgsdataprovider.h
Outdated
@@ -104,6 +104,7 @@ class CORE_EXPORT QgsDataProvider : public QObject | |||
struct ProviderOptions | |||
{ | |||
QgsCoordinateTransformContext transformContext; | |||
bool trustDatasourceConfig; //!< Trust datasource config (primary key unicity, geometry type and srid, etc). Improves provider load time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be more future-friendly if we also used a new flags setup here instead of bools. (Don't forget the "since" annotation too!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed my changes on struct ProviderOptions
and added ReadFlags
src/core/qgsmaplayer.h
Outdated
@@ -553,6 +553,7 @@ class CORE_EXPORT QgsMapLayer : public QObject | |||
enum ReadFlag | |||
{ | |||
FlagDontResolveLayers = 1 << 0, //!< Don't resolve layer paths or create data providers for layers. | |||
FlagTrustLayerMetadata = 1 << 1, //!< Trust layer metadata. Improves layer load time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FlagTrustLayerMetadata = 1 << 1, //!< Trust layer metadata. Improves layer load time. | |
FlagTrustLayerMetadata = 1 << 1, //!< Trust layer metadata. Improves layer load time by skipping expensive checks like ######### on layer load. Since QGIS 3.16 |
src/core/raster/qgsrasterlayer.cpp
Outdated
@@ -125,7 +125,7 @@ QgsRasterLayer::QgsRasterLayer( const QString &uri, | |||
QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 ); | |||
setProviderType( providerKey ); | |||
|
|||
QgsDataProvider::ProviderOptions providerOptions { options.transformContext }; | |||
QgsDataProvider::ProviderOptions providerOptions { options.transformContext, ( mReadFlags & QgsMapLayer::FlagTrustLayerMetadata ) ? true : false }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fragile way of constructing ProviderOptions -- if someone reorganised the members in the future then this code would break. Better to make an explicit constructor for ProviderOptions so that this is using stable api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed my changes on struct ProviderOptions
and added ReadFlags
@@ -628,18 +629,18 @@ class CORE_EXPORT QgsDataProvider : public QObject | |||
//! Sets error message | |||
void setError( const QgsError &error ) { mError = error;} | |||
|
|||
private: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change doesn't seem required -- can you revert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have moved mOptions
from private
to protected
because build stopped with the message
../src/providers/postgres/qgspostgresprovider.cpp:159:58: error: 'mOptions' is a private member of 'QgsDataProvider'
mUseEstimatedMetadata = mUri.useEstimatedMetadata() || mOptions.trustDatasourceConfig;
^
../src/core/qgsdataprovider.h:642:38: note: declared private here
QgsDataProvider::ProviderOptions mOptions;
^
../src/providers/postgres/qgspostgresprovider.cpp:1737:39: error: 'mOptions' is a private member of 'QgsDataProvider'
if ( mCheckPrimaryKeyUnicity || mOptions.trustDatasourceConfig )
^
../src/core/qgsdataprovider.h:642:38: note: declared private here
QgsDataProvider::ProviderOptions mOptions;
^
../src/providers/postgres/qgspostgresprovider.cpp:3740:8: error: 'mOptions' is a private member of 'QgsDataProvider'
if ( mOptions.trustDatasourceConfig )
^
../src/core/qgsdataprovider.h:642:38: note: declared private here
QgsDataProvider::ProviderOptions mOptions;
^
3 errors generated.
And I have moved mDataSourceURI
from private
to protected
because build generates a warning:
[130/2497] Building CXX object src/core/CMakeFiles/qgis_core.dir/qgsdataprovider.cpp.o
../src/core/qgsdataprovider.cpp:23:5: warning: field 'mDataSourceURI' will be initialized after field 'mOptions' [-Wreorder]
: mDataSourceURI( uri ),
^
1 warning generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have fixed it by created mReadFlags
af75ee1
to
191f04e
Compare
df5e221
to
a048bce
Compare
7dc27ea
to
8d4625c
Compare
Hi @nyalldawson, what do you thonk about ths flags implémentation ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, nice work!
The trust flag at the projetc level is only used to read vector layer extent from xml, not from provider. This flag was not available at the vector layer and data provider level. We propose a new QgsMapLayer reading flag to propagate the trust layer metadata prohect's read flag an d a new provider options to trust datasource config. Trusting the datasource config means that the provider can use estimated metadata, the primary key is unique and the detectable geometry type and srid are the same as the requested.
e09e7ae
to
02cff9f
Compare
Thanks @nyalldawson |
@pblottiere or @elpaso do you agree to merge ? |
tahnsk @pblottiere @elpaso -> Speed up QGIS Server ;-) |
Thanks to you @rldhont, very good work 👍 |
Description
The trust flag at the project level is only used to read vector layer extent from xml, not from provider.
This flag was not available at the vector layer and data provider level.
We propose a new QgsMapLayer reading flag to propagate the trust layer metadata prohect's read flag and a new provider flag to trust datasource config.
Trusting the datasource config means that the provider can use estimated metadata, the primary key is unique and the detectable geometry type and srid are the same as the requested.