Skip to content

Commit

Permalink
Now hopefully fixed expansion.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralph Gasser committed Apr 3, 2024
1 parent c5933aa commit f9501ef
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ class RelationExpander(

/* Fetch relation entries for the provided IDs. */
val ids = inputRetrieved.map { it.id }.toSet()
val (incoming, outgoing) = if (ids.isNotEmpty()) {
val (objects, subjects) = if (ids.isNotEmpty()) {
(if (this@RelationExpander.incomingRelations.isNotEmpty()) {
this@RelationExpander.retrievableReader.getConnections(emptyList(), this@RelationExpander.incomingRelations, ids)
} else {
emptySequence()
}.groupBy { it.third }
}.groupBy { it.first }

to

if (this@RelationExpander.outgoingRelations.isNotEmpty()) {
this@RelationExpander.retrievableReader.getConnections(ids, this@RelationExpander.outgoingRelations, emptyList())
} else {
emptySequence()
}.groupBy { it.first })
}.groupBy { it.third })
} else {
emptyMap<RetrievableId, List<Triple<RetrievableId,String,RetrievableId>>>() to emptyMap()
}

/* Collection IDs that are new and fetch corresponding retrievable. */
val newIds = (incoming.keys + outgoing.keys) - ids
val newRetrievables = if (newIds.isNotEmpty()) {
val newIds = (objects.keys + subjects.keys) - ids
val new = if (newIds.isNotEmpty()) {
retrievableReader.getAll(newIds.toList())
} else {
emptySequence()
Expand All @@ -64,13 +64,13 @@ class RelationExpander(
/* Iterate over input and emit each retrievable with expanded relationships. */
inputRetrieved.forEach {
/* Expand incoming relationships. */
for (inc in (incoming[it.id] ?: emptyList())) {
it.addAttribute(RelationshipAttribute(Relationship(inc.first to newRetrievables[inc.first], inc.second, inc.third to newRetrievables[inc.third])))
for (obj in (objects[it.id] ?: emptyList())) {
it.addAttribute(RelationshipAttribute(Relationship(obj.first to it, obj.second, obj.third to new[obj.third])))
}

/* Expand outgoing relationships. */
for (out in (outgoing[it.id] ?: emptyList())) {
it.addAttribute(RelationshipAttribute(Relationship(out.third to newRetrievables[out.third], out.second, out.first to newRetrievables[out.first])))
for (out in (subjects[it.id] ?: emptyList())) {
it.addAttribute(RelationshipAttribute(Relationship(out.first to new[out.third], out.second, out.first to it)))
}

/* Emit. */
Expand Down

0 comments on commit f9501ef

Please sign in to comment.