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

Fix cascade SQL cache remove loops forever on cyclic references #6137

Merged
merged 1 commit into from
Sep 3, 2024

Conversation

cvb941
Copy link
Contributor

@cvb941 cvb941 commented Sep 3, 2024

Should fix #6133

Copy link

netlify bot commented Sep 3, 2024

👷 Deploy request for apollo-android-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit f772c4a

Copy link
Contributor

@martinbonnin martinbonnin left a comment

Choose a reason for hiding this comment

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

Thanks!

Comment on lines +359 to +410
@Test
fun testCascadeDeleteWithSelfReference() {
// Creating a self-referencing record
cache.merge(
record = Record(
key = "selfRefKey",
fields = mapOf(
"field1" to "value1",
"selfRef" to CacheKey("selfRefKey"),
),
),
cacheHeaders = CacheHeaders.NONE,
)

val result = cache.remove(cacheKey = CacheKey("selfRefKey"), cascade = true)

assertTrue(result)
val record = cache.loadRecord("selfRefKey", CacheHeaders.NONE)
assertNull(record)
}

@Test
fun testCascadeDeleteWithCyclicReferences() {
// Creating two records that reference each other
cache.merge(
record = Record(
key = "key1",
fields = mapOf(
"field1" to "value1",
"refToKey2" to CacheKey("key2"),
),
),
cacheHeaders = CacheHeaders.NONE,
)

cache.merge(
record = Record(
key = "key2",
fields = mapOf(
"field1" to "value2",
"refToKey1" to CacheKey("key1"),
),
),
cacheHeaders = CacheHeaders.NONE,
)

val result = cache.remove(cacheKey = CacheKey("key1"), cascade = true)

assertTrue(result)
assertNull(cache.loadRecord("key1", CacheHeaders.NONE))
assertNull(cache.loadRecord("key2", CacheHeaders.NONE))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Very cool tests 👍

@martinbonnin martinbonnin merged commit 342b21c into apollographql:main Sep 3, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cascade cache remove loops forever on cyclic references
2 participants