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 optimistic rendering when deleting multiple records #9198

Merged
merged 1 commit into from
Dec 23, 2024

Conversation

ijreilly
Copy link
Collaborator

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This pull request modifies the optimistic rendering behavior when deleting multiple records in the Apollo cache management system.

  • Replaces array splice operations with filter in triggerUpdateRecordOptimisticEffectByBatch.ts for more predictable record removal
  • Changes record existence check from findIndex > -1 to find + isDefined for clearer intent
  • Improves edge case handling when removing records from the Apollo cache edges array
  • Maintains consistent behavior with single record deletion through triggerUpdateRecordOptimisticEffect.ts

The changes make the code more functional and less prone to mutation-related bugs, though with potential performance tradeoffs for large datasets.

1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +106 to +109
rootQueryNextEdges = rootQueryNextEdges.filter(
(cachedEdge) =>
readField('id', cachedEdge.node) !== updatedRecord.id,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

style: filter creates a new array on every iteration - for large deletions this could impact performance. Consider collecting IDs to remove first, then filtering once

@@ -105,7 +103,10 @@ export const triggerUpdateRecordOptimisticEffectByBatch = ({
}

if (updatedRecordShouldBeRemovedFromRootQueryEdges) {
rootQueryNextEdges.splice(updatedRecordIndexInRootQueryEdges, 1);
rootQueryNextEdges = rootQueryNextEdges.filter(
(cachedEdge) =>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

splicing was causing an issue here because it modified the indexes of elements in rootQueryNextEdges, which was problematic when there were multiple iterations

Copy link
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

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

LGTM

@Weiko Weiko merged commit 6abe735 into main Dec 23, 2024
22 checks passed
@Weiko Weiko deleted the fix-optimistic-rendering-deletion branch December 23, 2024 13:19
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.

2 participants