Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves the BaseEntityCache and BaseEntityRef #668

Merged
merged 9 commits into from
Dec 16, 2024
Merged

Conversation

idlira
Copy link
Contributor

@idlira idlira commented Dec 13, 2024

Description

  • BaseEntityCache
    Always use the ID stored in the reference to retrieve an item from the cache. Previously, if the reference was pre-loaded, that value was delivered instead.
  • BaseEntityRef
    fetchValue() is now deprecated and replaced by fetchCachedValue() + forceFetchValue(). Same for the *FromSecondary variants.

Marked as BREAKING since usages of fetchValue() and fetchValueFromSecondary() in tagliatelle templates might lead to build warnings.

To keep the previous semantics, simply replace fetchValue() by fetchCachedValue() and fetchValueFromSecondary() by fetchCachedValueFromSecondary()

Additional Notes

  • This PR fixes or works on following ticket(s): SIRI-1039

Checklist

  • Code change has been tested and works locally
  • Code was formatted via IntelliJ and follows SonarLint & best practices

`fetch(BaseEntityRef)` delivered the value contained in the provided reference, regardless if a newer version was available in the cache.

This would become visible if the entity where the reference was read also comes from an outdated cache.

Basically, making this just a commodity method to fetchById.

Fixes: SIRI-1039
fetchValue is now deprecated and falls back to fetchCachedValue

Fixes: SIRI-1039
fetchValueFromSecondary is now deprecated and falls back to fetchCachedValueFromSecondary

Fixes: SIRI-1039
@idlira idlira added 🧬 Enhancement Contains new features 💣 BREAKING CHANGE Contains non-backwards compatible changes to public methods or changes the behavior of existing code and removed 💣 BREAKING CHANGE Contains non-backwards compatible changes to public methods or changes the behavior of existing code labels Dec 13, 2024
since we cannot guarantee the order in which tests are executed, we strip a portion of the expected name (so matching "Parent 3" or "Parent 3.1")

Fixes: SIRI-1039
@@ -31,24 +31,24 @@ class SmartQueryKotlinTest {
@Test
fun `queryList returns all entities`() {
val smartQueryTestEntity = oma.select(SmartQueryTestEntity::class.java)
.orderAsc(SmartQueryTestEntity.TEST_NUMBER)
.orderAsc(SmartQueryTestEntity.TEST_NUMBER)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks as if we need to optimise our Kotlin formatting rules 😇

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are (or rather should be when the IDE is configured correctly) defined by the Kotlin language themselves. It is highly discouraged to stray away from it and create a customized formatting ruleset.
But this formatting looks like the language default isn't applied here.
Maybe we can change something in sirius-parent to make usage easier.

assertEquals(listOf("Parent 2"), result.stream().map { x -> x.name }.collect(Collectors.toList()))
assertEquals(
listOf("Parent 2", "Parent 3"),
result.stream().map { x -> x.name.substring(0, 8) }.collect(Collectors.toList())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Add a comment explaining this?
  • Protect against x.name.length < 8?
  • Compare sets (or sorted lists) if we cannot guarantee the order?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a comment about why we substring.
For the other comments: The data used in these test cases are inserted during the class setup, therefore controlled data, which means:

  1. x.name.length < 8 cannot happen
  2. The order of items will be guaranteed by the ID (they are inserted in order). What we cannot guarantee is the oder in which tests are executed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isolated tests would be great :-)

@@ -31,24 +31,24 @@ class SmartQueryKotlinTest {
@Test
fun `queryList returns all entities`() {
val smartQueryTestEntity = oma.select(SmartQueryTestEntity::class.java)
.orderAsc(SmartQueryTestEntity.TEST_NUMBER)
.orderAsc(SmartQueryTestEntity.TEST_NUMBER)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are (or rather should be when the IDE is configured correctly) defined by the Kotlin language themselves. It is highly discouraged to stray away from it and create a customized formatting ruleset.
But this formatting looks like the language default isn't applied here.
Maybe we can change something in sirius-parent to make usage easier.

assertEquals(listOf("Parent 2"), result.stream().map { x -> x.name }.collect(Collectors.toList()))
assertEquals(
listOf("Parent 2", "Parent 3"),
result.stream().map { x -> x.name.substring(0, 8) }.collect(Collectors.toList())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isolated tests would be great :-)

Moves the actual lookup to the "forced" methods, making the calls a bit more natural

Fixes: SIRI-1039
@idlira idlira merged commit fa6b319 into develop Dec 16, 2024
3 checks passed
@idlira idlira deleted the ili/SIRI-1039 branch December 16, 2024 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💣 BREAKING CHANGE Contains non-backwards compatible changes to public methods or changes the behavior of existing code 🧬 Enhancement Contains new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants