Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: Timeout for multiple Gravsearch queries (DEV-1379) (#2234)
  • Loading branch information
irinaschubert committed Oct 5, 2022
1 parent a67c98f commit c63567b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
Expand Up @@ -216,37 +216,41 @@ object QueryTraverser {
* @param appActor a reference to the appActor to retrieve a [[ProjectADM]] by a shortcode.
* @return a sequence of ontology IRIs which relate to the input RDF entity.
*/
private def resolveEntity(entity: Entity, map: Map[SmartIri, SmartIri], appActor: ActorRef): Seq[SmartIri] =
private def resolveEntity(entity: Entity, map: Map[SmartIri, SmartIri], appActor: ActorRef)(implicit
ec: ExecutionContext
): Future[Seq[SmartIri]] =
entity match {
case IriRef(iri, _) => {
val internal = iri.toOntologySchema(InternalSchema)
val maybeOntoIri = map.get(internal)
maybeOntoIri match {
// if the map contains an ontology IRI corresponding to the entity IRI, then this can be returned
case Some(iri) => Seq(iri)
case Some(iri) => Future(Seq(iri))
case None => {
// if the map doesn't contain a corresponding ontology IRI, then the entity IRI points to a resource or value
// in that case, all ontologies of the project, to which the entity belongs, should be returned.
val shortcode = internal.getProjectCode
shortcode match {
case None => Seq.empty
case _ => {
case None => Future(Seq.empty)
case Some(_) => {
// find the project with the shortcode
val projectFuture = appActor
.ask(ProjectGetADM(ProjectIdentifierADM(maybeShortcode = shortcode)))
.mapTo[Option[ProjectADM]]
val projectMaybe = Await.result(projectFuture, 1.second)
projectMaybe match {
case None => Seq.empty
// return all ontologies of the project
case Some(project) => project.ontologies.map(_.toSmartIri)
}

for {
projectMaybe <- appActor
.ask(ProjectGetADM(ProjectIdentifierADM(maybeShortcode = shortcode)))
.mapTo[Option[ProjectADM]]
projectOntologies = projectMaybe match {
case None => Seq.empty
// return all ontologies of the project
case Some(project) => project.ontologies.map(_.toSmartIri)
}
} yield projectOntologies
}
}
}
}
}
case _ => Seq.empty
case _ => Future(Seq.empty)
}

/**
Expand Down Expand Up @@ -286,9 +290,11 @@ object QueryTraverser {
// from the cache, get the map from entity to the ontology where the entity is defined
entityMap = ontoCache.entityDefinedInOntology
// resolve all entities from the WHERE clause to the ontology where they are defined
relevantOntologies = entities.flatMap(resolveEntity(_, entityMap, storeManager)).toSet
relevantOntologies <-
Future.sequence(entities.map(resolveEntity(_, entityMap, storeManager)(executionContext)))
relevantOntologiesSet = relevantOntologies.flatten.toSet
relevantOntologiesMaybe =
relevantOntologies match {
relevantOntologiesSet match {
case Nil => None // if nothing was found, then None should be returned
case ontologies =>
// if only knora-base was found, then None should be returned too
Expand Down
Expand Up @@ -208,16 +208,14 @@ class ProjectsResponderADM(responderData: ResponderData) extends Responder(respo
*
* @param identifier the IRI, shortname, or shortcode of the project.
* @param skipCache if `true`, doesn't check the cache and tries to retrieve the project directly from the triplestore
* @return information about the project as a [[ProjectInfoV1]].
* @return information about the project as an optional [[ProjectADM]].
*/
private def getSingleProjectADM(
def getSingleProjectADM(
identifier: ProjectIdentifierADM,
skipCache: Boolean = false
): Future[Option[ProjectADM]] =
tracedFuture("admin-get-project") {

// log.debug("getSingleProjectADM - projectIRI: {}", projectIri)

log.debug(
s"getSingleProjectADM - id: {}, skipCache: {}",
identifier.value,
Expand Down Expand Up @@ -251,16 +249,14 @@ class ProjectsResponderADM(responderData: ResponderData) extends Responder(respo
* as a [[ProjectGetResponseADM]].
*
* @param identifier the IRI, shortname, or shortcode of the project.
*
* @param requestingUser the user making the request.
* @return information about the project as a [[ProjectInfoResponseV1]].
* @return information about the project as a [[ProjectGetResponseADM]].
* @throws NotFoundException when no project for the given IRI can be found
*/
private def getSingleProjectADMRequest(
identifier: ProjectIdentifierADM,
requestingUser: UserADM
): Future[ProjectGetResponseADM] =
// log.debug("getSingleProjectADMRequest - maybeIri: {}, maybeShortname: {}, maybeShortcode: {}", maybeIri, maybeShortname, maybeShortcode)
for {
maybeProject: Option[ProjectADM] <- getSingleProjectADM(
identifier = identifier
Expand Down

0 comments on commit c63567b

Please sign in to comment.