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

Trust layer metadata propagation #38464

Merged
merged 4 commits into from
Sep 11, 2020

Conversation

rldhont
Copy link
Contributor

@rldhont rldhont commented Aug 26, 2020

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.

@rldhont rldhont added Feature API API improvement only, no visible user interface changes Data Provider Related to specific vector, raster or mesh data providers labels Aug 26, 2020
@rldhont rldhont added this to the 3.16 (Feature) milestone Aug 26, 2020
@rldhont
Copy link
Contributor Author

rldhont commented Aug 26, 2020

@mdouchin @dmarteau Can you take a look at the code ? thanks

@@ -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.
Copy link
Collaborator

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!)

Copy link
Contributor Author

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

@@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

@@ -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 };
Copy link
Collaborator

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.

Copy link
Contributor Author

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:
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

@rldhont rldhont force-pushed the trust-layer-metadata-propagation branch from af75ee1 to 191f04e Compare August 27, 2020 12:03
@zacharlie zacharlie added the Changelog Items that are queued to appear in the visual changelog - remove after harvesting label Aug 27, 2020
@rldhont rldhont force-pushed the trust-layer-metadata-propagation branch 2 times, most recently from df5e221 to a048bce Compare September 1, 2020 09:19
@rldhont rldhont force-pushed the trust-layer-metadata-propagation branch 2 times, most recently from 7dc27ea to 8d4625c Compare September 8, 2020 09:30
@rldhont
Copy link
Contributor Author

rldhont commented Sep 8, 2020

Hi @nyalldawson, what do you thonk about ths flags implémentation ?

Copy link
Collaborator

@nyalldawson nyalldawson left a 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.
@rldhont rldhont force-pushed the trust-layer-metadata-propagation branch from e09e7ae to 02cff9f Compare September 9, 2020 07:48
@rldhont
Copy link
Contributor Author

rldhont commented Sep 10, 2020

Thanks @nyalldawson

@rldhont
Copy link
Contributor Author

rldhont commented Sep 11, 2020

@pblottiere or @elpaso do you agree to merge ?

@elpaso elpaso merged commit 63d8ee7 into qgis:master Sep 11, 2020
@rldhont
Copy link
Contributor Author

rldhont commented Sep 11, 2020

tahnsk @pblottiere @elpaso -> Speed up QGIS Server ;-)

@pblottiere
Copy link
Member

tahnsk @pblottiere @elpaso -> Speed up QGIS Server ;-)

Thanks to you @rldhont, very good work 👍

@zacharlie zacharlie added ChangelogHarvested This PR description has been harvested in the Changelog already. and removed Changelog Items that are queued to appear in the visual changelog - remove after harvesting labels Sep 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API API improvement only, no visible user interface changes ChangelogHarvested This PR description has been harvested in the Changelog already. Data Provider Related to specific vector, raster or mesh data providers Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants