Skip to content
Permalink
Browse files

fix(api-v1): Optimise SPARQL queries. (#1814)

  • Loading branch information
benjamingeer committed Feb 4, 2021
1 parent 9c1a70a commit 4edc27cc64000e599b4b89db8ace1eee7e088908
Showing with 162 additions and 64 deletions.
  1. +8 −3 .../src/main/twirl/org/knora/webapi/messages/twirl/queries/sparql/v1/findResourceWithValue.scala.txt
  2. +28 −11 ...pi/src/main/twirl/org/knora/webapi/messages/twirl/queries/sparql/v1/findValueInVersions.scala.txt
  3. +19 −7 webapi/src/main/twirl/org/knora/webapi/messages/twirl/queries/sparql/v1/getContextStandard.scala.txt
  4. +13 −6 ...n/twirl/org/knora/webapi/messages/twirl/queries/sparql/v1/getIncomingReferencesStandard.scala.txt
  5. +9 −5 webapi/src/main/twirl/org/knora/webapi/messages/twirl/queries/sparql/v1/getRegionsStandard.scala.txt
  6. +28 −9 ...rg/knora/webapi/messages/twirl/queries/sparql/v1/getResourcePropertiesAndValuesStandard.scala.txt
  7. +6 −2 ...twirl/org/knora/webapi/messages/twirl/queries/sparql/v1/getResourceSearchResultStandard.scala.txt
  8. +4 −1 ...in/twirl/org/knora/webapi/messages/twirl/queries/sparql/v1/getResourcesByProjectAndType.scala.txt
  9. +18 −6 webapi/src/main/twirl/org/knora/webapi/messages/twirl/queries/sparql/v1/getValueStandard.scala.txt
  10. +8 −3 .../main/twirl/org/knora/webapi/messages/twirl/queries/sparql/v1/getVersionHistoryStandard.scala.txt
  11. +8 −2 webapi/src/main/twirl/org/knora/webapi/messages/twirl/queries/sparql/v1/isPartOfStandard.scala.txt
  12. +0 −1 .../src/main/twirl/org/knora/webapi/messages/twirl/queries/sparql/v1/searchExtendedGraphDB.scala.txt
  13. +6 −6 ...src/main/twirl/org/knora/webapi/messages/twirl/queries/sparql/v1/searchExtendedStandard.scala.txt
  14. +7 −2 ...src/main/twirl/org/knora/webapi/messages/twirl/queries/sparql/v1/searchFulltextStandard.scala.txt
@@ -40,14 +40,19 @@ SELECT ?resource ?project ?property
WHERE {
BIND(IRI("@searchValueIri") as ?searchValue)

?searchValue knora-base:isDeleted false .

@* Find something that links to searchValue, and make sure it's a Resource. *@

?resource ?property ?searchValue ;
knora-base:isDeleted false ;
rdf:type ?resourceClass .
?resourceClass rdfs:subClassOf* knora-base:Resource .
?property rdfs:subPropertyOf* knora-base:hasValue .
?resource knora-base:attachedToProject ?project .

FILTER NOT EXISTS {
?searchValue knora-base:isDeleted true .
}

FILTER NOT EXISTS {
?resource knora-base:isDeleted true .
}
}
@@ -43,17 +43,23 @@ SELECT ?objPred ?objObj ?predStandoff ?objStandoff
FROM <http://www.ontotext.com/explicit>
}
WHERE {
BIND(IRI("@resourceIri") as ?resource)
BIND(IRI("@propertyIri") as ?property)
BIND(IRI("@searchValueIri") as ?searchValue)

{
?resource ?property ?currentValue ;
knora-base:isDeleted false .
?currentValue knora-base:previousValue* ?searchValue ;
knora-base:isDeleted false .
BIND(IRI("@resourceIri") as ?resource)
BIND(IRI("@propertyIri") as ?property)
BIND(IRI("@searchValueIri") as ?searchValue)

?resource ?property ?currentValue .
?currentValue knora-base:previousValue* ?searchValue .
?searchValue ?objPred ?objObj .

FILTER NOT EXISTS {
?resource knora-base:isDeleted true .
}

FILTER NOT EXISTS {
?currentValue knora-base:isDeleted true .
}

FILTER(?objPred != knora-base:attachedToProject)

OPTIONAL {
@@ -63,11 +69,22 @@ WHERE {
}
UNION
{
BIND(IRI("@resourceIri") as ?resource)
BIND(IRI("@propertyIri") as ?property)
BIND(IRI("@searchValueIri") as ?searchValue)

?resource ?property ?currentValue ;
knora-base:isDeleted false ;
knora-base:attachedToProject ?resourceProject .
?currentValue knora-base:previousValue* ?searchValue ;
knora-base:isDeleted false .

?currentValue knora-base:previousValue* ?searchValue .

FILTER NOT EXISTS {
?resource knora-base:isDeleted true .
}

FILTER NOT EXISTS {
?currentValue knora-base:isDeleted true .
}

@* Return the project of the resource that contains the value. *@

@@ -56,17 +56,15 @@ SELECT ?sourceObject
WHERE {
BIND(IRI("@resourceIri") as ?resource)

?resource rdf:type ?resourceClass ;
knora-base:isDeleted false .
?resource rdf:type ?resourceClass .

?resourceClass rdfs:subClassOf* knora-base:Resource .

# Find something that relates to this resource via knora-base:isPartOf.

?linkingProp rdfs:subPropertyOf* knora-base:isPartOf .

?sourceObject ?linkingProp ?resource ;
knora-base:isDeleted false .
?sourceObject ?linkingProp ?resource .

OPTIONAL {
?seqProp rdfs:subPropertyOf* knora-base:seqnum .
@@ -87,16 +85,30 @@ WHERE {
rdf:subject ?sourceObject ;
rdf:predicate ?linkingProp ;
rdf:object ?resource ;
knora-base:isDeleted false ;
knora-base:attachedToUser ?linkValueCreator ;
knora-base:hasPermissions ?linkValuePermissions .

FILTER NOT EXISTS {
?resource knora-base:isDeleted true .
}

FILTER NOT EXISTS {
?sourceObject knora-base:isDeleted true .
}

FILTER NOT EXISTS {
?linkValue knora-base:isDeleted true .
}

OPTIONAL {
?fileValueProp rdfs:subPropertyOf* knora-base:hasFileValue .
?sourceObject ?fileValueProp ?fileValue .

?fileValue a knora-base:StillImageFileValue ;
knora-base:isDeleted false .
?fileValue a knora-base:StillImageFileValue .

FILTER NOT EXISTS {
?fileValue knora-base:isDeleted true .
}

?fileValue knora-base:internalMimeType ?internalMimeType ;
knora-base:originalFilename ?originalFilename ;
@@ -52,17 +52,21 @@ WHERE {

BIND(IRI("@resourceIri") as ?resource)

?resource knora-base:isDeleted false .

?linkProp rdfs:subPropertyOf* knora-base:hasLinkTo .

FILTER NOT EXISTS {
?linkProp rdfs:subPropertyOf* knora-base:isPartOf .
}

?referringResource ?linkProp ?resource ;
knora-base:isDeleted false .
FILTER NOT EXISTS {
?resource knora-base:isDeleted true .
}

?referringResource ?linkProp ?resource .

FILTER NOT EXISTS {
?referringResource knora-base:isDeleted true .
}
} LIMIT 50
}

@@ -84,8 +88,11 @@ WHERE {
?prop rdfs:subPropertyOf* knora-base:hasLinkToValue .
?referringResource ?prop ?obj .

?obj knora-base:isDeleted false ;
?objPred ?objObj .
?obj ?objPred ?objObj .

FILTER NOT EXISTS {
?obj knora-base:isDeleted true .
}

BIND(true as ?isLinkValue)
}
@@ -38,17 +38,21 @@ PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?region ?resclass ?regionObjectPermissions ?owner ?project
WHERE {
BIND(IRI("@resourceIri") as ?resource)
?resource knora-base:isDeleted false .

?linkingProp rdfs:subPropertyOf* knora-base:isRegionOf .
?region ?linkingProp ?resource .

?region knora-base:isDeleted false .

?region a ?resclass .
?resclass rdfs:subClassOf* knora-base:Region .
?region a ?resclass .

?region knora-base:attachedToUser ?owner ;
knora-base:attachedToProject ?project ;
knora-base:hasPermissions ?regionObjectPermissions .

FILTER NOT EXISTS {
?resource knora-base:isDeleted true .
}

FILTER NOT EXISTS {
?region knora-base:isDeleted true .
}
}
@@ -38,10 +38,13 @@ SELECT ?prop ?isLinkProp ?isLinkValueProp ?obj ?objPred ?objObj ?predStandoff ?o
WHERE {
BIND(IRI("@resourceIri") as ?resource)

?resource rdf:type ?resourceClass ;
knora-base:isDeleted false .
?resource rdf:type ?resourceClass .
?resourceClass rdfs:subClassOf* knora-base:Resource .

FILTER NOT EXISTS {
?resource knora-base:isDeleted true .
}

{
@* Get properties that point to Value objects. *@

@@ -63,29 +66,41 @@ WHERE {
@* Get the project of the containing resource. *@

?resource ?prop ?obj .
?obj knora-base:isDeleted false .

FILTER NOT EXISTS {
?obj knora-base:isDeleted true .
}

?resource knora-base:attachedToProject ?resourceProject .
BIND(knora-base:attachedToProject AS ?objPred)
BIND(COALESCE(?valueProject, ?resourceProject) AS ?objObj)
BIND(COALESCE(?valueProject, ?resourceProject) AS ?objObj)
}
UNION
{
@* Get the value's standoff markup nodes if it has any. *@

?resource ?prop ?obj .
?obj knora-base:isDeleted false .

FILTER NOT EXISTS {
?obj knora-base:isDeleted true .
}

?obj a knora-base:TextValue .
BIND(knora-base:valueHasStandoff AS ?objPred)
?obj ?objPred ?objObj .
?obj ?objPred ?objObj .
?objObj ?predStandoff ?objStandoff .
}
UNION
{
@* Get any other statements about the value. *@

?resource ?prop ?obj .
?obj knora-base:isDeleted false .
?obj ?objPred ?objObj .

FILTER NOT EXISTS {
?obj knora-base:isDeleted true .
}

?obj ?objPred ?objObj .

FILTER(!(?objPred = knora-base:attachedToProject || ?objPred = knora-base:valueHasStandoff))
}
@@ -98,7 +113,11 @@ WHERE {
BIND(true AS ?isLinkProp)

?resource ?prop ?obj .
?obj knora-base:isDeleted false .

FILTER NOT EXISTS {
?obj knora-base:isDeleted true .
}

?obj ?objPred ?objObj .
}
}
@@ -68,7 +68,9 @@ WHERE {
}
}

?resourceIri knora-base:isDeleted false .
FILTER NOT EXISTS {
?resourceIri knora-base:isDeleted true .
}

@restypeIriOption match {

@@ -98,9 +100,11 @@ WHERE {
?resourceIri ?property ?valueObjectIri .
?property knora-base:objectClassConstraint knora-base:TextValue .
?valueObjectIri knora-base:valueHasString ?valueString ;
knora-base:isDeleted false ;
knora-base:valueHasOrder ?valueOrder .

FILTER NOT EXISTS {
?valueObjectIri knora-base:isDeleted true .
}
}

}
@@ -43,6 +43,9 @@ WHERE {
BIND(IRI("@resType") as ?resType)

?s rdf:type ?resType ;
knora-base:isDeleted false ;
knora-base:attachedToProject ?projectIri .

FILTER NOT EXISTS {
?s knora-base:isDeleted true .
}
}
@@ -41,10 +41,16 @@ WHERE {
?resourceProp rdfs:subPropertyOf* knora-base:hasValue .

{
?resource ?resourceProp ?obj ;
knora-base:isDeleted false .
?resource ?resourceProp ?obj .

FILTER NOT EXISTS {
?resource knora-base:isDeleted true .
}

FILTER NOT EXISTS {
?obj knora-base:isDeleted true .
}

?obj knora-base:isDeleted false .
?obj ?objPred ?objObj .

FILTER(?objPred != knora-base:attachedToProject)
@@ -58,10 +64,16 @@ WHERE {
{
@* Return the project of the resource that contains the value. *@

?resource ?resourceProp ?obj ;
knora-base:isDeleted false .
?resource ?resourceProp ?obj .

FILTER NOT EXISTS {
?resource knora-base:isDeleted true .
}

FILTER NOT EXISTS {
?obj knora-base:isDeleted true .
}

?obj knora-base:isDeleted false .
?resource knora-base:attachedToProject ?resourceProject .

BIND(knora-base:attachedToProject AS ?objPred)
@@ -46,17 +46,22 @@ WHERE {
BIND(IRI("@propertyIri") AS ?prop)
BIND(IRI("@currentValueIri") AS ?currentValue)

?resource knora-base:isDeleted false .
?currentValue knora-base:hasPermissions ?valuePermissions .

?currentValue knora-base:isDeleted false ;
knora-base:hasPermissions ?valuePermissions .
FILTER NOT EXISTS {
?currentValue knora-base:isDeleted true .
}

?resource ?prop ?currentValue .
?prop rdfs:subPropertyOf* knora-base:hasValue .
?resource knora-base:attachedToProject ?project .

?currentValue knora-base:previousValue* ?value .

FILTER NOT EXISTS {
?resource knora-base:isDeleted true .
}

OPTIONAL {
?value knora-base:valueCreationDate ?valueCreationDate .
}

0 comments on commit 4edc27c

Please sign in to comment.