From 6892cf3770fd0765fe334f3dcdfab1cf18fc0ac5 Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Tue, 26 Sep 2023 10:04:51 +0200 Subject: [PATCH] perf: Disable loading of dimension values for preview query --- CHANGELOG.md | 2 ++ app/graphql/queries/data-cubes.graphql | 25 +++++++++++++-- app/graphql/query-hooks.ts | 42 +++++++++++++++++++++++--- app/graphql/resolver-types.ts | 17 +++++++++-- app/graphql/resolvers/rdf.ts | 6 +++- app/graphql/schema.graphql | 13 ++++++++ 6 files changed, 94 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6c57eed0c..e496e2c0b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ You can also check the [release page](https://github.com/visualize-admin/visuali - Fixes - Cube checker now correctly checks if dimensions are present +- Performance + - Dataset preview should now load quicker as we no longer fetch dimension values along with it # [3.22.6] - 2023-09-19 diff --git a/app/graphql/queries/data-cubes.graphql b/app/graphql/queries/data-cubes.graphql index ed35a11a34..7599f0f0de 100644 --- a/app/graphql/queries/data-cubes.graphql +++ b/app/graphql/queries/data-cubes.graphql @@ -7,7 +7,12 @@ fragment dimensionMetadata on Dimension { dataType scaleType order - values(sourceType: $sourceType, sourceUrl: $sourceUrl, filters: $filters) + values( + sourceType: $sourceType + sourceUrl: $sourceUrl + filters: $filters + disableLoad: $isPreview + ) unit related { iri @@ -120,6 +125,7 @@ query DataCubePreview( $locale: String! $latest: Boolean $filters: Filters + $isPreview: Boolean = true ) { dataCubeByIri( iri: $iri @@ -127,15 +133,24 @@ query DataCubePreview( sourceUrl: $sourceUrl locale: $locale latest: $latest + isPreview: $isPreview ) { iri title description publicationStatus - dimensions(sourceType: $sourceType, sourceUrl: $sourceUrl) { + dimensions( + sourceType: $sourceType + sourceUrl: $sourceUrl + disableValuesLoad: $isPreview + ) { ...dimensionMetadata } - measures(sourceType: $sourceType, sourceUrl: $sourceUrl) { + measures( + sourceType: $sourceType + sourceUrl: $sourceUrl + disableValuesLoad: $isPreview + ) { ...dimensionMetadata } observations(sourceType: $sourceType, sourceUrl: $sourceUrl, limit: 10) { @@ -193,6 +208,7 @@ query Components( $latest: Boolean $filters: Filters $componentIris: [String!] + $isPreview: Boolean = false ) { dataCubeByIri( iri: $iri @@ -200,11 +216,13 @@ query Components( sourceUrl: $sourceUrl locale: $locale latest: $latest + isPreview: $isPreview ) { dimensions( sourceType: $sourceType sourceUrl: $sourceUrl componentIris: $componentIris + disableValuesLoad: $isPreview ) { ...dimensionMetadata } @@ -212,6 +230,7 @@ query Components( sourceType: $sourceType sourceUrl: $sourceUrl componentIris: $componentIris + disableValuesLoad: $isPreview ) { ...dimensionMetadata } diff --git a/app/graphql/query-hooks.ts b/app/graphql/query-hooks.ts index 3970f43926..6722ba4462 100644 --- a/app/graphql/query-hooks.ts +++ b/app/graphql/query-hooks.ts @@ -64,6 +64,7 @@ export type DataCubeDimensionsArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; componentIris?: Maybe>; + disableValuesLoad?: Maybe; }; @@ -78,6 +79,7 @@ export type DataCubeMeasuresArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; componentIris?: Maybe>; + disableValuesLoad?: Maybe; }; export type DataCubeOrganization = { @@ -142,6 +144,7 @@ export type DimensionValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -183,6 +186,7 @@ export type GeoCoordinatesDimensionValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -214,6 +218,7 @@ export type GeoShapesDimensionValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -258,6 +263,7 @@ export type NominalDimensionValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -291,6 +297,7 @@ export type NumericalMeasureValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -340,6 +347,7 @@ export type OrdinalDimensionValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -369,6 +377,7 @@ export type OrdinalMeasureValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -397,6 +406,7 @@ export type QueryDataCubeByIriArgs = { latest?: Maybe; filters?: Maybe; componentIris?: Maybe>; + isPreview?: Maybe; }; @@ -485,6 +495,7 @@ export type StandardErrorDimensionValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -516,6 +527,7 @@ export type TemporalDimensionValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -545,6 +557,7 @@ export type TemporalOrdinalDimensionValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -834,6 +847,7 @@ export type DataCubePreviewQueryVariables = Exact<{ locale: Scalars['String']; latest?: Maybe; filters?: Maybe; + isPreview?: Maybe; }>; @@ -891,6 +905,7 @@ export type ComponentsQueryVariables = Exact<{ latest?: Maybe; filters?: Maybe; componentIris?: Maybe | Scalars['String']>; + isPreview?: Maybe; }>; @@ -1153,7 +1168,12 @@ export const DimensionMetadataFragmentDoc = gql` dataType scaleType order - values(sourceType: $sourceType, sourceUrl: $sourceUrl, filters: $filters) + values( + sourceType: $sourceType + sourceUrl: $sourceUrl + filters: $filters + disableLoad: $isPreview + ) unit related { iri @@ -1271,22 +1291,31 @@ export function useDataCubesQuery(options: Omit({ query: DataCubesDocument, ...options }); }; export const DataCubePreviewDocument = gql` - query DataCubePreview($iri: String!, $sourceType: String!, $sourceUrl: String!, $locale: String!, $latest: Boolean, $filters: Filters) { + query DataCubePreview($iri: String!, $sourceType: String!, $sourceUrl: String!, $locale: String!, $latest: Boolean, $filters: Filters, $isPreview: Boolean = true) { dataCubeByIri( iri: $iri sourceType: $sourceType sourceUrl: $sourceUrl locale: $locale latest: $latest + isPreview: $isPreview ) { iri title description publicationStatus - dimensions(sourceType: $sourceType, sourceUrl: $sourceUrl) { + dimensions( + sourceType: $sourceType + sourceUrl: $sourceUrl + disableValuesLoad: $isPreview + ) { ...dimensionMetadata } - measures(sourceType: $sourceType, sourceUrl: $sourceUrl) { + measures( + sourceType: $sourceType + sourceUrl: $sourceUrl + disableValuesLoad: $isPreview + ) { ...dimensionMetadata } observations(sourceType: $sourceType, sourceUrl: $sourceUrl, limit: 10) { @@ -1340,18 +1369,20 @@ export function useDataCubeMetadataQuery(options: Omit({ query: DataCubeMetadataDocument, ...options }); }; export const ComponentsDocument = gql` - query Components($iri: String!, $sourceType: String!, $sourceUrl: String!, $locale: String!, $latest: Boolean, $filters: Filters, $componentIris: [String!]) { + query Components($iri: String!, $sourceType: String!, $sourceUrl: String!, $locale: String!, $latest: Boolean, $filters: Filters, $componentIris: [String!], $isPreview: Boolean = false) { dataCubeByIri( iri: $iri sourceType: $sourceType sourceUrl: $sourceUrl locale: $locale latest: $latest + isPreview: $isPreview ) { dimensions( sourceType: $sourceType sourceUrl: $sourceUrl componentIris: $componentIris + disableValuesLoad: $isPreview ) { ...dimensionMetadata } @@ -1359,6 +1390,7 @@ export const ComponentsDocument = gql` sourceType: $sourceType sourceUrl: $sourceUrl componentIris: $componentIris + disableValuesLoad: $isPreview ) { ...dimensionMetadata } diff --git a/app/graphql/resolver-types.ts b/app/graphql/resolver-types.ts index d70feb5b66..b18b46d970 100644 --- a/app/graphql/resolver-types.ts +++ b/app/graphql/resolver-types.ts @@ -66,6 +66,7 @@ export type DataCubeDimensionsArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; componentIris?: Maybe>; + disableValuesLoad?: Maybe; }; @@ -80,6 +81,7 @@ export type DataCubeMeasuresArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; componentIris?: Maybe>; + disableValuesLoad?: Maybe; }; export type DataCubeOrganization = { @@ -144,6 +146,7 @@ export type DimensionValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -185,6 +188,7 @@ export type GeoCoordinatesDimensionValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -216,6 +220,7 @@ export type GeoShapesDimensionValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -260,6 +265,7 @@ export type NominalDimensionValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -293,6 +299,7 @@ export type NumericalMeasureValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -342,6 +349,7 @@ export type OrdinalDimensionValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -371,6 +379,7 @@ export type OrdinalMeasureValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -399,6 +408,7 @@ export type QueryDataCubeByIriArgs = { latest?: Maybe; filters?: Maybe; componentIris?: Maybe>; + isPreview?: Maybe; }; @@ -487,6 +497,7 @@ export type StandardErrorDimensionValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -518,6 +529,7 @@ export type TemporalDimensionValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -547,6 +559,7 @@ export type TemporalOrdinalDimensionValuesArgs = { sourceType: Scalars['String']; sourceUrl: Scalars['String']; filters?: Maybe; + disableLoad?: Maybe; }; @@ -636,6 +649,7 @@ export type ResolversTypes = ResolversObject<{ DataCube: ResolverTypeWrapper; String: ResolverTypeWrapper; Int: ResolverTypeWrapper; + Boolean: ResolverTypeWrapper; DataCubeOrganization: ResolverTypeWrapper; DataCubePublicationStatus: DataCubePublicationStatus; DataCubeResult: ResolverTypeWrapper & { dataCube: ResolversTypes['DataCube'] }>; @@ -645,7 +659,6 @@ export type ResolversTypes = ResolversObject<{ DataCubeTheme: ResolverTypeWrapper; DatasetCount: ResolverTypeWrapper; Dimension: ResolverTypeWrapper; - Boolean: ResolverTypeWrapper; DimensionValue: ResolverTypeWrapper; FilterValue: ResolverTypeWrapper; Filters: ResolverTypeWrapper; @@ -679,6 +692,7 @@ export type ResolversParentTypes = ResolversObject<{ DataCube: ResolvedDataCube; String: Scalars['String']; Int: Scalars['Int']; + Boolean: Scalars['Boolean']; DataCubeOrganization: DataCubeOrganization; DataCubeResult: Omit & { dataCube: ResolversParentTypes['DataCube'] }; Float: Scalars['Float']; @@ -686,7 +700,6 @@ export type ResolversParentTypes = ResolversObject<{ DataCubeTheme: DataCubeTheme; DatasetCount: DatasetCount; Dimension: ResolvedDimension; - Boolean: Scalars['Boolean']; DimensionValue: Scalars['DimensionValue']; FilterValue: Scalars['FilterValue']; Filters: Scalars['Filters']; diff --git a/app/graphql/resolvers/rdf.ts b/app/graphql/resolvers/rdf.ts index 0809838140..95e80be326 100644 --- a/app/graphql/resolvers/rdf.ts +++ b/app/graphql/resolvers/rdf.ts @@ -333,7 +333,11 @@ export const hierarchy: NonNullable = async ( export const dimensionValues: NonNullable< NonNullable["values"] -> = async (parent, { filters }, { setup }, info) => { +> = async (parent, { filters, disableLoad }, { setup }, info) => { + if (disableLoad) { + return []; + } + const { loaders, sparqlClient, cache } = await setup(info); // Different loader if we have filters or not const loader = getDimensionValuesLoader( diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index a926324bc8..93f23e45a1 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -57,6 +57,7 @@ type DataCube { sourceType: String! sourceUrl: String! componentIris: [String!] + disableValuesLoad: Boolean ): [Dimension!]! dimensionByIri( iri: String! @@ -67,6 +68,7 @@ type DataCube { sourceType: String! sourceUrl: String! componentIris: [String!] + disableValuesLoad: Boolean ): [Measure!]! themes: [DataCubeTheme!]! } @@ -102,6 +104,7 @@ interface Dimension { sourceType: String! sourceUrl: String! filters: Filters + disableLoad: Boolean ): [DimensionValue!]! related: [RelatedDimension!] hierarchy(sourceType: String!, sourceUrl: String!): [HierarchyValue!] @@ -128,6 +131,7 @@ type GeoCoordinatesDimension implements Dimension { sourceType: String! sourceUrl: String! filters: Filters + disableLoad: Boolean ): [DimensionValue!]! geoCoordinates: [GeoCoordinates!] related: [RelatedDimension!] @@ -154,6 +158,7 @@ type GeoShapesDimension implements Dimension { sourceType: String! sourceUrl: String! filters: Filters + disableLoad: Boolean ): [DimensionValue!]! geoShapes: GeoShapes related: [RelatedDimension!] @@ -174,6 +179,7 @@ type NominalDimension implements Dimension { sourceType: String! sourceUrl: String! filters: Filters + disableLoad: Boolean ): [DimensionValue!]! related: [RelatedDimension!] hierarchy(sourceType: String!, sourceUrl: String!): [HierarchyValue!] @@ -193,6 +199,7 @@ type OrdinalDimension implements Dimension { sourceType: String! sourceUrl: String! filters: Filters + disableLoad: Boolean ): [DimensionValue!]! related: [RelatedDimension!] hierarchy(sourceType: String!, sourceUrl: String!): [HierarchyValue!] @@ -212,6 +219,7 @@ type StandardErrorDimension implements Dimension { sourceType: String! sourceUrl: String! filters: Filters + disableLoad: Boolean ): [DimensionValue!]! related: [RelatedDimension!] hierarchy(sourceType: String!, sourceUrl: String!): [HierarchyValue!] @@ -243,6 +251,7 @@ type TemporalDimension implements Dimension { sourceType: String! sourceUrl: String! filters: Filters + disableLoad: Boolean ): [DimensionValue!]! related: [RelatedDimension!] hierarchy(sourceType: String!, sourceUrl: String!): [HierarchyValue!] @@ -262,6 +271,7 @@ type TemporalOrdinalDimension implements Dimension { sourceType: String! sourceUrl: String! filters: Filters + disableLoad: Boolean ): [DimensionValue!]! related: [RelatedDimension!] hierarchy(sourceType: String!, sourceUrl: String!): [HierarchyValue!] @@ -287,6 +297,7 @@ type NumericalMeasure implements Dimension { sourceType: String! sourceUrl: String! filters: Filters + disableLoad: Boolean ): [DimensionValue!]! related: [RelatedDimension!] hierarchy(sourceType: String!, sourceUrl: String!): [HierarchyValue!] @@ -306,6 +317,7 @@ type OrdinalMeasure implements Dimension { sourceType: String! sourceUrl: String! filters: Filters + disableLoad: Boolean ): [DimensionValue!]! related: [RelatedDimension!] hierarchy(sourceType: String!, sourceUrl: String!): [HierarchyValue!] @@ -355,6 +367,7 @@ type Query { latest: Boolean = true filters: Filters componentIris: [String!] + isPreview: Boolean ): DataCube possibleFilters( iri: String!