Lazy Relation - #125
Merged
Merged
Conversation
Gabriel-Darbord
requested changes
Sep 3, 2026
Gabriel-Darbord
left a comment
Member
There was a problem hiding this comment.
Thanks Benoit.
I'm a bit afraid of the current limitations, I can foresee weird bugs happening in the future, but fixing them would require modifying other parts of Fame, so I think this is fine for a first version.
I have just a few change requests: skip tests rather than comment them, and format the code.
Co-authored-by: Gabriel Darbord <78592838+Gabriel-Darbord@users.noreply.github.com>
Co-authored-by: Gabriel Darbord <78592838+Gabriel-Darbord@users.noreply.github.com>
Co-authored-by: Gabriel Darbord <78592838+Gabriel-Darbord@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For incremental loading, we might need to perform lazy loading of some relation.
To do so, this PR introduces a first implementation of lazyness for relations.
Design
The idea is to apply the update at how Fame slots are working to introduce an extensibility endpoint instead of modifying the existing model accessors.
The modification must work on existing relation generated by the generator.
The idea is to use polymorphism to check if we are in a lazy relation, or in a normal relation.
Implementation
The PR introduces the class
FMLazyValuethat represent a relation/Value that needs to be resolved when first accessed.For instance, when installed on
methodsofFamixJavaClass, it will computes a custom block that can be used to do whatever things, and fill the future methods relationship.API
You can execute the following piece of code to install the lazy relation on a slot of a specific entity.
relationwill contains theFMSlotMultivalueLinkthat need to be used (forMultirelation)FMLazyOneHolderthat will (forOnerelation)entitythe entity that hold the slotOr the
OnerelationPolymorphism
I introduce the method
fmValueReadFrom:owner:inObjectandFMLazyValue. It is called when reading the value of aFMRelationSlot.The
FMRelationSlotare used to represent the relation in Moose.I dislike the idea of modyfing the
read:ofFMRelationSlot.I can see two others options:
This two other version would have allowed to remove the polymorphism dispatch (and so performance).
Consideration
We ask ourselves: What is the behavior of setting up an array to a Multi-Multi lazy oppositite relationships?
Motivation example.
Should the hero have killed 1 dragon (the
dragonvariable), 2 dragons (the lazy ones), 3 dragons (lazy + variable).We decided for three.
The
accessorshould not remove first lazyness setup.The
dragonvariable cannot be ignore.Future consideration: we might think of an API to explicitly control the behavior
Architecture
classDiagram FMLazyValue <|-- FMLazyMany FMLazyValue <|-- FMLazyOne FMLazyOne "1" --> "1" FMLazyOneHolder : valueLimitation
The current design of
FMManyandFMOnemakes things difficult in some cases.In particular, using our design, updating the opposite of a Lazy One relation will not remove the Lazyness of the One side.
Example:
When executing
entity owner, it will trigger again the lazy part of the code.This is because
FMOne>>#writeInverse:to:uses an inner API instead of the default write API to avoid recursive call of the two side update of Fame