From 7443d0ddc03a253d30cbab12c00a9f0617ad342a Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Thu, 2 May 2024 10:29:57 +0200 Subject: [PATCH 1/6] refactor: Create wrapper for dimension values loading --- app/rdf/queries.ts | 89 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 10 deletions(-) diff --git a/app/rdf/queries.ts b/app/rdf/queries.ts index 027308ecc..83a1212a0 100644 --- a/app/rdf/queries.ts +++ b/app/rdf/queries.ts @@ -195,21 +195,64 @@ const getCubeDimensionsValues = async ( filters?: Filters; cache: LRUCache | undefined; } +) => { + const { minMaxDimensions, regularDimensions } = resolvedDimensions.reduce<{ + minMaxDimensions: ResolvedDimension[]; + regularDimensions: ResolvedDimension[]; + }>( + (acc, dimension) => { + if (shouldLoadMinMaxValues(dimension)) { + acc.minMaxDimensions.push(dimension); + } else { + acc.regularDimensions.push(dimension); + } + + return acc; + }, + { minMaxDimensions: [], regularDimensions: [] } + ); + + const result = await Promise.all([ + getMinMaxDimensionsValues(minMaxDimensions, { + sparqlClient, + cache, + }), + getRegularDimensionsValues(regularDimensions, { + sparqlClient, + filters, + cache, + }), + ]); + + return result + .flat() + .sort( + (a, b) => + resolvedDimensions.indexOf(a.resolvedDimension) - + resolvedDimensions.indexOf(b.resolvedDimension) + ) + .map(({ values }) => values); +}; + +const getMinMaxDimensionsValues = async ( + resolvedDimensions: ResolvedDimension[], + { + sparqlClient, + cache, + }: { + sparqlClient: ParsingClient; + cache: LRUCache | undefined; + } ) => { return await Promise.all( resolvedDimensions.map(async (resolvedDimension) => { - if (shouldLoadMinMaxValues(resolvedDimension)) { - return await getMinMaxDimensionValues(resolvedDimension, { + return { + resolvedDimension, + values: await getMinMaxDimensionValues(resolvedDimension, { sparqlClient, cache, - }); - } else { - return await getRegularDimensionValues(resolvedDimension, { - sparqlClient, - filters, - cache, - }); - } + }), + }; }) ); }; @@ -289,6 +332,32 @@ const getMinMaxDimensionValues = async ( return []; }; +const getRegularDimensionsValues = async ( + resolvedDimensions: ResolvedDimension[], + { + sparqlClient, + filters, + cache, + }: { + sparqlClient: ParsingClient; + filters?: Filters; + cache: LRUCache | undefined; + } +) => { + return await Promise.all( + resolvedDimensions.map(async (resolvedDimension) => { + return { + resolvedDimension, + values: await getRegularDimensionValues(resolvedDimension, { + sparqlClient, + filters, + cache, + }), + }; + }) + ); +}; + const getRegularDimensionValues = async ( resolvedDimension: ResolvedDimension, { From 0a89525aecb22696d8ae5fefbef04fe0dafe2d2d Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Thu, 2 May 2024 11:30:14 +0200 Subject: [PATCH 2/6] refactor: Fetch values for every dimension at the same time --- app/rdf/queries.ts | 44 +++------ app/rdf/query-dimension-values.ts | 143 +++++++++++++++++++++++++++++- 2 files changed, 150 insertions(+), 37 deletions(-) diff --git a/app/rdf/queries.ts b/app/rdf/queries.ts index 83a1212a0..0b929ad96 100644 --- a/app/rdf/queries.ts +++ b/app/rdf/queries.ts @@ -9,7 +9,6 @@ import { LRUCache } from "typescript-lru-cache"; import { FilterValueMulti, Filters } from "@/config-types"; import { - DimensionValue, Observation, ObservationValue, parseObservationValue, @@ -31,7 +30,7 @@ import { parseRelatedDimensions, } from "@/rdf/parse"; import { - loadDimensionValuesWithMetadata, + loadDimensionsValuesWithMetadata, loadMaxDimensionValue, loadMinMaxDimensionValues, } from "@/rdf/query-dimension-values"; @@ -196,6 +195,7 @@ const getCubeDimensionsValues = async ( cache: LRUCache | undefined; } ) => { + const dimensionIris = resolvedDimensions.map((d) => d.data.iri); const { minMaxDimensions, regularDimensions } = resolvedDimensions.reduce<{ minMaxDimensions: ResolvedDimension[]; regularDimensions: ResolvedDimension[]; @@ -228,8 +228,8 @@ const getCubeDimensionsValues = async ( .flat() .sort( (a, b) => - resolvedDimensions.indexOf(a.resolvedDimension) - - resolvedDimensions.indexOf(b.resolvedDimension) + dimensionIris.indexOf(a.dimensionIri) - + dimensionIris.indexOf(b.dimensionIri) ) .map(({ values }) => values); }; @@ -247,7 +247,7 @@ const getMinMaxDimensionsValues = async ( return await Promise.all( resolvedDimensions.map(async (resolvedDimension) => { return { - resolvedDimension, + dimensionIri: resolvedDimension.data.iri, values: await getMinMaxDimensionValues(resolvedDimension, { sparqlClient, cache, @@ -344,35 +344,11 @@ const getRegularDimensionsValues = async ( cache: LRUCache | undefined; } ) => { - return await Promise.all( - resolvedDimensions.map(async (resolvedDimension) => { - return { - resolvedDimension, - values: await getRegularDimensionValues(resolvedDimension, { - sparqlClient, - filters, - cache, - }), - }; - }) - ); -}; - -const getRegularDimensionValues = async ( - resolvedDimension: ResolvedDimension, - { - sparqlClient, - filters, - cache, - }: { - sparqlClient: ParsingClient; - filters?: Filters; - cache: LRUCache | undefined; - } -): Promise => { - const { cube, data, locale } = resolvedDimension; - return await loadDimensionValuesWithMetadata(cube.term?.value!, { - dimensionIri: data.iri, + // `cube` and `locale` are the same for all dimensions + const { cube, locale } = resolvedDimensions[0]; + const cubeIri = cube.term?.value!; + return await loadDimensionsValuesWithMetadata(cubeIri, { + dimensionIris: resolvedDimensions.map((d) => d.data.iri), cubeDimensions: cube.dimensions, sparqlClient, filters, diff --git a/app/rdf/query-dimension-values.ts b/app/rdf/query-dimension-values.ts index 02e8a8f15..c8256ab02 100644 --- a/app/rdf/query-dimension-values.ts +++ b/app/rdf/query-dimension-values.ts @@ -74,6 +74,143 @@ const getFilterOrder = (filter: FilterValue) => { return 0; }; +type LoadDimensionsValuesProps = { + dimensionIris: string[]; + cubeDimensions: CubeDimension[]; + sparqlClient: ParsingClient; + filters?: Filters; + locale: string; + cache: LRUCache | undefined; +}; + +export async function loadDimensionsValuesWithMetadata( + cubeIri: string, + props: LoadDimensionsValuesProps +) { + const { + dimensionIris, + cubeDimensions, + sparqlClient, + filters, + locale, + cache, + } = props; + + const dimensionQueries = dimensionIris.map((dimensionIri) => { + const filterList = getFiltersList(filters, dimensionIri); + const queryFilters = getQueryFilters( + filterList, + cubeDimensions, + dimensionIri + ); + + if (!cubeDimensions.find((d) => d.path?.value === dimensionIri)) { + throw new Error(`Dimension not found: ${dimensionIri}`); + } + + return `${ + queryFilters + ? "" + : `{ #pragma evaluate on + SELECT ?dimensionIri ?value WHERE { + VALUES ?dimensionIri { <${dimensionIri}> } + <${cubeIri}> cube:observationConstraint/sh:property ?dimension . + ?dimension sh:path ?dimensionIri . + ?dimension sh:in/rdf:rest*/rdf:first ?maybeVersionedValue . + OPTIONAL { + ?dimension schema:version ?version . + ?maybeVersionedValue schema:sameAs ?maybeUnversionedValue . + } + BIND(COALESCE(?maybeUnversionedValue, ?maybeVersionedValue) as ?value) + } + } UNION` + } { + { #pragma evaluate on + SELECT DISTINCT ?dimensionIri ?value WHERE { + FILTER(?dimension NOT IN (rdf:type, cube:observedBy)) + ${ + queryFilters + ? `<${cubeIri}> cube:observationConstraint/sh:property ?dimension . + ?dimension sh:path ?dimensionIri . + FILTER(?dimensionIri NOT IN (rdf:type, cube:observedBy))` + : ` + VALUES ?dimensionIri { <${dimensionIri}> } + <${cubeIri}> cube:observationConstraint/sh:property ?dimension . + ?dimension sh:path ?dimensionIri . + FILTER(NOT EXISTS{ ?dimension sh:in ?in . })` + } + <${cubeIri}> cube:observationSet/cube:observation ?observation . + ?observation ?dimensionIri ?maybeVersionedValue . + OPTIONAL { + ?dimension schema:version ?version . + ?maybeVersionedValue schema:sameAs ?maybeUnversionedValue . + } + BIND(COALESCE(?maybeUnversionedValue, ?maybeVersionedValue) as ?value) + ${queryFilters} + } + } + }`; + }); + + const query = `PREFIX cube: +PREFIX geo: +PREFIX schema: +PREFIX sh: +PREFIX rdf: + +CONSTRUCT { + ?dimensionIri rdf:first ?value . + ?value + schema:name ?name ; + schema:alternateName ?alternateName ; + schema:description ?description ; + schema:identifier ?identifier ; + schema:position ?position ; + schema:color ?color ; + geo:hasGeometry ?geometry ; + schema:latitude ?latitude ; + schema:longitude ?longitude . +} WHERE { + ${dimensionQueries.join("\nUNION ")} + ${buildLocalizedSubQuery("value", "schema:name", "name", { + locale, + })} + ${buildLocalizedSubQuery("value", "schema:description", "description", { + locale, + })} + ${buildLocalizedSubQuery("value", "schema:alternateName", "alternateName", { + locale, + })} + OPTIONAL { ?value schema:identifier ?identifier . } + OPTIONAL { ?value schema:position ?position . } + OPTIONAL { ?value schema:color ?color . } + OPTIONAL { ?value geo:hasGeometry ?geometry . } + OPTIONAL { ?value schema:latitude ?latitude . } + OPTIONAL { ?value schema:longitude ?longitude . } +}`; + + return await executeWithCache( + sparqlClient, + query, + () => sparqlClient.query.construct(query, { operation: "postUrlencoded" }), + (quads) => { + const result: { [dimensionIri: string]: DimensionValue[] } = + Object.fromEntries(dimensionIris.map((iri) => [iri, []])); + + for (const q of quads.filter((q) => q.predicate.equals(ns.rdf.first))) { + const dimensionIri = q.subject.value; + result[dimensionIri]?.push(parseDimensionValue(q, quads)); + } + + return Object.entries(result).map(([dimensionIri, values]) => ({ + dimensionIri, + values, + })); + }, + cache + ); +} + type LoadDimensionValuesProps = { dimensionIri: string; cubeDimensions: CubeDimension[]; @@ -89,10 +226,10 @@ type LoadDimensionValuesProps = { * Filters on other dimensions can be passed. * */ -export async function loadDimensionValuesWithMetadata( +export const loadDimensionValuesWithMetadata = async ( cubeIri: string, props: LoadDimensionValuesProps -): Promise { +): Promise => { const { dimensionIri, cubeDimensions, sparqlClient, filters, locale, cache } = props; const filterList = getFiltersList(filters, dimensionIri); @@ -192,7 +329,7 @@ CONSTRUCT { }, cache ); -} +}; const parseDimensionValue = ( valueQuad: Quad, From e8ba4a92383e5e9c9e68dcf064cbe4385984167a Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Fri, 3 May 2024 12:05:31 +0200 Subject: [PATCH 3/6] perf: Remove OPTIONAL --- app/rdf/query-dimension-values.ts | 45 ++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/app/rdf/query-dimension-values.ts b/app/rdf/query-dimension-values.ts index c8256ab02..53a76e963 100644 --- a/app/rdf/query-dimension-values.ts +++ b/app/rdf/query-dimension-values.ts @@ -116,36 +116,57 @@ export async function loadDimensionsValuesWithMetadata( VALUES ?dimensionIri { <${dimensionIri}> } <${cubeIri}> cube:observationConstraint/sh:property ?dimension . ?dimension sh:path ?dimensionIri . - ?dimension sh:in/rdf:rest*/rdf:first ?maybeVersionedValue . - OPTIONAL { - ?dimension schema:version ?version . - ?maybeVersionedValue schema:sameAs ?maybeUnversionedValue . - } - BIND(COALESCE(?maybeUnversionedValue, ?maybeVersionedValue) as ?value) + ?dimension schema:version ?version . + ?dimension sh:in/rdf:rest*/rdf:first/schema:sameAs ?value . + } + } UNION { + SELECT ?dimensionIri ?value WHERE { + VALUES ?dimensionIri { <${dimensionIri}> } + <${cubeIri}> cube:observationConstraint/sh:property ?dimension . + ?dimension sh:path ?dimensionIri . + FILTER NOT EXISTS { ?dimension schema:version ?version . } + ?dimension sh:in/rdf:rest*/rdf:first ?value . } } UNION` } { { #pragma evaluate on SELECT DISTINCT ?dimensionIri ?value WHERE { - FILTER(?dimension NOT IN (rdf:type, cube:observedBy)) ${ queryFilters ? `<${cubeIri}> cube:observationConstraint/sh:property ?dimension . ?dimension sh:path ?dimensionIri . + ?dimension schema:version ?version . FILTER(?dimensionIri NOT IN (rdf:type, cube:observedBy))` : ` VALUES ?dimensionIri { <${dimensionIri}> } <${cubeIri}> cube:observationConstraint/sh:property ?dimension . ?dimension sh:path ?dimensionIri . + ?dimension schema:version ?version . FILTER(NOT EXISTS{ ?dimension sh:in ?in . })` } <${cubeIri}> cube:observationSet/cube:observation ?observation . - ?observation ?dimensionIri ?maybeVersionedValue . - OPTIONAL { - ?dimension schema:version ?version . - ?maybeVersionedValue schema:sameAs ?maybeUnversionedValue . + ?observation ?dimensionIri ?versionedValue . + ?versionedValue schema:sameAs ?value . + ${queryFilters} + } + } + } UNION { + { #pragma evaluate on + SELECT DISTINCT ?dimensionIri ?value WHERE { + ${ + queryFilters + ? `<${cubeIri}> cube:observationConstraint/sh:property ?dimension . + ?dimension sh:path ?dimensionIri . + FILTER(?dimensionIri NOT IN (rdf:type, cube:observedBy))` + : ` + VALUES ?dimensionIri { <${dimensionIri}> } + <${cubeIri}> cube:observationConstraint/sh:property ?dimension . + ?dimension sh:path ?dimensionIri . + FILTER(NOT EXISTS{ ?dimension sh:in ?in . })` } - BIND(COALESCE(?maybeUnversionedValue, ?maybeVersionedValue) as ?value) + <${cubeIri}> cube:observationSet/cube:observation ?observation . + ?observation ?dimensionIri ?value . + FILTER NOT EXISTS { ?value schema:version ?version . } ${queryFilters} } } From 2b3440ece3a7e3acde10edb0addfe444d35c1da6 Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Mon, 6 May 2024 13:06:30 +0200 Subject: [PATCH 4/6] fix: Need to unpack metadata from versioned dimension values --- app/rdf/query-dimension-values.ts | 61 +++++++++++++++++++------------ 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/app/rdf/query-dimension-values.ts b/app/rdf/query-dimension-values.ts index 53a76e963..732166493 100644 --- a/app/rdf/query-dimension-values.ts +++ b/app/rdf/query-dimension-values.ts @@ -112,25 +112,27 @@ export async function loadDimensionsValuesWithMetadata( queryFilters ? "" : `{ #pragma evaluate on - SELECT ?dimensionIri ?value WHERE { + SELECT ?dimensionIri ?versionedValue ?unversionedValue WHERE { VALUES ?dimensionIri { <${dimensionIri}> } <${cubeIri}> cube:observationConstraint/sh:property ?dimension . ?dimension sh:path ?dimensionIri . ?dimension schema:version ?version . - ?dimension sh:in/rdf:rest*/rdf:first/schema:sameAs ?value . + ?dimension sh:in/rdf:rest*/rdf:first ?versionedValue . + ?versionedValue schema:sameAs ?unversionedValue . } } UNION { - SELECT ?dimensionIri ?value WHERE { + SELECT ?dimensionIri ?versionedValue ?unversionedValue WHERE { VALUES ?dimensionIri { <${dimensionIri}> } <${cubeIri}> cube:observationConstraint/sh:property ?dimension . ?dimension sh:path ?dimensionIri . FILTER NOT EXISTS { ?dimension schema:version ?version . } - ?dimension sh:in/rdf:rest*/rdf:first ?value . + ?dimension sh:in/rdf:rest*/rdf:first ?versionedValue . + BIND(?versionedValue as ?unversionedValue) } } UNION` } { { #pragma evaluate on - SELECT DISTINCT ?dimensionIri ?value WHERE { + SELECT DISTINCT ?dimensionIri ?versionedValue ?unversionedValue WHERE { ${ queryFilters ? `<${cubeIri}> cube:observationConstraint/sh:property ?dimension . @@ -146,13 +148,13 @@ export async function loadDimensionsValuesWithMetadata( } <${cubeIri}> cube:observationSet/cube:observation ?observation . ?observation ?dimensionIri ?versionedValue . - ?versionedValue schema:sameAs ?value . + ?versionedValue schema:sameAs ?unversionedValue . ${queryFilters} } } } UNION { { #pragma evaluate on - SELECT DISTINCT ?dimensionIri ?value WHERE { + SELECT DISTINCT ?dimensionIri ?versionedValue ?unversionedValue WHERE { ${ queryFilters ? `<${cubeIri}> cube:observationConstraint/sh:property ?dimension . @@ -165,8 +167,9 @@ export async function loadDimensionsValuesWithMetadata( FILTER(NOT EXISTS{ ?dimension sh:in ?in . })` } <${cubeIri}> cube:observationSet/cube:observation ?observation . - ?observation ?dimensionIri ?value . - FILTER NOT EXISTS { ?value schema:version ?version . } + ?observation ?dimensionIri ?versionedValue . + FILTER NOT EXISTS { ?dimension schema:version ?version . } + BIND(?versionedValue as ?unversionedValue) ${queryFilters} } } @@ -180,8 +183,8 @@ PREFIX sh: PREFIX rdf: CONSTRUCT { - ?dimensionIri rdf:first ?value . - ?value + ?dimensionIri rdf:first ?unversionedValue . + ?unversionedValue schema:name ?name ; schema:alternateName ?alternateName ; schema:description ?description ; @@ -193,21 +196,31 @@ CONSTRUCT { schema:longitude ?longitude . } WHERE { ${dimensionQueries.join("\nUNION ")} - ${buildLocalizedSubQuery("value", "schema:name", "name", { - locale, - })} - ${buildLocalizedSubQuery("value", "schema:description", "description", { - locale, - })} - ${buildLocalizedSubQuery("value", "schema:alternateName", "alternateName", { + ${buildLocalizedSubQuery("versionedValue", "schema:name", "name", { locale, })} - OPTIONAL { ?value schema:identifier ?identifier . } - OPTIONAL { ?value schema:position ?position . } - OPTIONAL { ?value schema:color ?color . } - OPTIONAL { ?value geo:hasGeometry ?geometry . } - OPTIONAL { ?value schema:latitude ?latitude . } - OPTIONAL { ?value schema:longitude ?longitude . } + ${buildLocalizedSubQuery( + "versionedValue", + "schema:description", + "description", + { + locale, + } + )} + ${buildLocalizedSubQuery( + "versionedValue", + "schema:alternateName", + "alternateName", + { + locale, + } + )} + OPTIONAL { ?versionedValue schema:identifier ?identifier . } + OPTIONAL { ?versionedValue schema:position ?position . } + OPTIONAL { ?versionedValue schema:color ?color . } + OPTIONAL { ?versionedValue geo:hasGeometry ?geometry . } + OPTIONAL { ?versionedValue schema:latitude ?latitude . } + OPTIONAL { ?versionedValue schema:longitude ?longitude . } }`; return await executeWithCache( From b59063cbc1109f9f0ecf6458735c4a367674efed Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Tue, 7 May 2024 09:47:18 +0200 Subject: [PATCH 5/6] perf: Optimize dimensions values query --- app/rdf/query-dimension-values.ts | 59 +++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/app/rdf/query-dimension-values.ts b/app/rdf/query-dimension-values.ts index 732166493..f3884248a 100644 --- a/app/rdf/query-dimension-values.ts +++ b/app/rdf/query-dimension-values.ts @@ -131,46 +131,67 @@ export async function loadDimensionsValuesWithMetadata( } } UNION` } { - { #pragma evaluate on + { SELECT DISTINCT ?dimensionIri ?versionedValue ?unversionedValue WHERE { + { #pragma evaluate on + SELECT ?observation WHERE { + ${ + queryFilters + ? `<${cubeIri}> cube:observationConstraint/sh:property ?dimension . + ?dimension sh:path ?dimensionIri . + ?dimension schema:version ?version . + FILTER(?dimensionIri NOT IN (rdf:type, cube:observedBy))` + : `VALUES ?dimensionIri { <${dimensionIri}> } + <${cubeIri}> cube:observationConstraint/sh:property ?dimension . + ?dimension sh:path ?dimensionIri . + ?dimension schema:version ?version . + FILTER NOT EXISTS { ?dimension sh:in ?in . }` + } + <${cubeIri}> cube:observationSet/cube:observation ?observation . + ${queryFilters} + } + } ${ queryFilters ? `<${cubeIri}> cube:observationConstraint/sh:property ?dimension . ?dimension sh:path ?dimensionIri . - ?dimension schema:version ?version . FILTER(?dimensionIri NOT IN (rdf:type, cube:observedBy))` - : ` - VALUES ?dimensionIri { <${dimensionIri}> } - <${cubeIri}> cube:observationConstraint/sh:property ?dimension . - ?dimension sh:path ?dimensionIri . - ?dimension schema:version ?version . - FILTER(NOT EXISTS{ ?dimension sh:in ?in . })` + : `VALUES ?dimensionIri { <${dimensionIri}> }` } - <${cubeIri}> cube:observationSet/cube:observation ?observation . ?observation ?dimensionIri ?versionedValue . ?versionedValue schema:sameAs ?unversionedValue . - ${queryFilters} } } } UNION { - { #pragma evaluate on + { SELECT DISTINCT ?dimensionIri ?versionedValue ?unversionedValue WHERE { + { #pragma evaluate on + SELECT ?observation WHERE { + ${ + queryFilters + ? `<${cubeIri}> cube:observationConstraint/sh:property ?dimension . + ?dimension sh:path ?dimensionIri . + FILTER NOT EXISTS { ?dimension schema:version ?version . } + FILTER(?dimensionIri NOT IN (rdf:type, cube:observedBy))` + : `VALUES ?dimensionIri { <${dimensionIri}> } + <${cubeIri}> cube:observationConstraint/sh:property ?dimension . + ?dimension sh:path ?dimensionIri . + FILTER NOT EXISTS { ?dimension schema:version ?version . } + FILTER NOT EXISTS { ?dimension sh:in ?in . }` + } + <${cubeIri}> cube:observationSet/cube:observation ?observation . + ${queryFilters} + } + } ${ queryFilters ? `<${cubeIri}> cube:observationConstraint/sh:property ?dimension . ?dimension sh:path ?dimensionIri . FILTER(?dimensionIri NOT IN (rdf:type, cube:observedBy))` - : ` - VALUES ?dimensionIri { <${dimensionIri}> } - <${cubeIri}> cube:observationConstraint/sh:property ?dimension . - ?dimension sh:path ?dimensionIri . - FILTER(NOT EXISTS{ ?dimension sh:in ?in . })` + : `VALUES ?dimensionIri { <${dimensionIri}> }` } - <${cubeIri}> cube:observationSet/cube:observation ?observation . ?observation ?dimensionIri ?versionedValue . - FILTER NOT EXISTS { ?dimension schema:version ?version . } BIND(?versionedValue as ?unversionedValue) - ${queryFilters} } } }`; From d099617a595b05207193d26a8d5de5db93519660 Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Fri, 14 Jun 2024 08:25:01 +0200 Subject: [PATCH 6/6] perf: Constraint relevant dimension values query parts to one dimension --- app/rdf/query-dimension-values.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/rdf/query-dimension-values.ts b/app/rdf/query-dimension-values.ts index f3884248a..b44946bad 100644 --- a/app/rdf/query-dimension-values.ts +++ b/app/rdf/query-dimension-values.ts @@ -137,10 +137,10 @@ export async function loadDimensionsValuesWithMetadata( SELECT ?observation WHERE { ${ queryFilters - ? `<${cubeIri}> cube:observationConstraint/sh:property ?dimension . + ? `VALUES ?dimensionIri { <${dimensionIri}> } + <${cubeIri}> cube:observationConstraint/sh:property ?dimension . ?dimension sh:path ?dimensionIri . - ?dimension schema:version ?version . - FILTER(?dimensionIri NOT IN (rdf:type, cube:observedBy))` + ?dimension schema:version ?version .` : `VALUES ?dimensionIri { <${dimensionIri}> } <${cubeIri}> cube:observationConstraint/sh:property ?dimension . ?dimension sh:path ?dimensionIri . @@ -153,9 +153,9 @@ export async function loadDimensionsValuesWithMetadata( } ${ queryFilters - ? `<${cubeIri}> cube:observationConstraint/sh:property ?dimension . - ?dimension sh:path ?dimensionIri . - FILTER(?dimensionIri NOT IN (rdf:type, cube:observedBy))` + ? `VALUES ?dimensionIri { <${dimensionIri}> } + <${cubeIri}> cube:observationConstraint/sh:property ?dimension . + ?dimension sh:path ?dimensionIri .` : `VALUES ?dimensionIri { <${dimensionIri}> }` } ?observation ?dimensionIri ?versionedValue . @@ -169,10 +169,10 @@ export async function loadDimensionsValuesWithMetadata( SELECT ?observation WHERE { ${ queryFilters - ? `<${cubeIri}> cube:observationConstraint/sh:property ?dimension . + ? `VALUES ?dimensionIri { <${dimensionIri}> } + <${cubeIri}> cube:observationConstraint/sh:property ?dimension . ?dimension sh:path ?dimensionIri . - FILTER NOT EXISTS { ?dimension schema:version ?version . } - FILTER(?dimensionIri NOT IN (rdf:type, cube:observedBy))` + FILTER NOT EXISTS { ?dimension schema:version ?version . }` : `VALUES ?dimensionIri { <${dimensionIri}> } <${cubeIri}> cube:observationConstraint/sh:property ?dimension . ?dimension sh:path ?dimensionIri . @@ -185,9 +185,9 @@ export async function loadDimensionsValuesWithMetadata( } ${ queryFilters - ? `<${cubeIri}> cube:observationConstraint/sh:property ?dimension . - ?dimension sh:path ?dimensionIri . - FILTER(?dimensionIri NOT IN (rdf:type, cube:observedBy))` + ? `VALUES ?dimensionIri { <${dimensionIri}> } + <${cubeIri}> cube:observationConstraint/sh:property ?dimension . + ?dimension sh:path ?dimensionIri .` : `VALUES ?dimensionIri { <${dimensionIri}> }` } ?observation ?dimensionIri ?versionedValue .