-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix computing diff on large resources during updates (#4684)
* Fix computing diff on large resources during updates * Fix case where the context is defined but has no @base * Fix compilation --------- Co-authored-by: Simon Dumas <[email protected]>
- Loading branch information
Showing
17 changed files
with
300 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/resources/DetectChange.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package ch.epfl.bluebrain.nexus.delta.sdk.resources | ||
|
||
import cats.effect.IO | ||
import ch.epfl.bluebrain.nexus.delta.rdf.IriOrBNode.Iri | ||
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.CompactedJsonLd | ||
import ch.epfl.bluebrain.nexus.delta.sdk.jsonld.JsonLdAssembly | ||
import ch.epfl.bluebrain.nexus.delta.sdk.model.jsonld.RemoteContextRef | ||
import ch.epfl.bluebrain.nexus.delta.sdk.resources.DetectChange.Current | ||
import ch.epfl.bluebrain.nexus.delta.sdk.resources.model.ResourceState | ||
import io.circe.Json | ||
|
||
/** | ||
* Detect if the new json-ld state introduces changes compared to the current state | ||
*/ | ||
trait DetectChange { | ||
def apply(newValue: JsonLdAssembly, currentState: ResourceState): IO[Boolean] = | ||
apply( | ||
newValue, | ||
Current(currentState.types, currentState.source, currentState.compacted, currentState.remoteContexts) | ||
) | ||
|
||
def apply(newValue: JsonLdAssembly, current: Current): IO[Boolean] | ||
} | ||
|
||
object DetectChange { | ||
|
||
final case class Current( | ||
types: Set[Iri], | ||
source: Json, | ||
compacted: CompactedJsonLd, | ||
remoteContexts: Set[RemoteContextRef] | ||
) | ||
|
||
private val Disabled = new DetectChange { | ||
|
||
override def apply(newValue: JsonLdAssembly, current: Current): IO[Boolean] = IO.pure(true) | ||
} | ||
|
||
/** | ||
* Default implementation | ||
* | ||
* There will be a change if: | ||
* - If there is a change in the resource types | ||
* - If there is a change in one of the remote JSON-LD contexts | ||
* - If there is a change in the local JSON-LD context | ||
* - If there is a change in the rest of the payload | ||
* | ||
* The implementation uses `IO.cede` as comparing source can induce expensive work in the case of large payloads. | ||
*/ | ||
private val Impl = new DetectChange { | ||
|
||
override def apply(newValue: JsonLdAssembly, current: Current): IO[Boolean] = | ||
IO.cede | ||
.as( | ||
newValue.types != current.types || | ||
newValue.remoteContexts != current.remoteContexts || | ||
newValue.compacted.ctx != current.compacted.ctx || | ||
newValue.source != current.source | ||
) | ||
.guarantee(IO.cede) | ||
} | ||
|
||
def apply(enabled: Boolean): DetectChange = if (enabled) Impl else Disabled | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.