-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Update total count on record deletion #8366
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR modifies the Apollo cache management to properly handle total record counts during deletion operations.
- Added logic in
triggerUpdateRecordOptimisticEffect.ts
to updatetotalCount
based on edge differences when records are removed - Ensures cache stays in sync by subtracting removed records from
totalCount
when records no longer match filters - Handles both soft deletion (via
deletedAt
) and filter-based removal in a single consistent way - Maintains cache consistency by updating counts alongside edge modifications
1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile
...enty-front/src/modules/apollo/optimistic-effect/utils/triggerUpdateRecordOptimisticEffect.ts
Show resolved
Hide resolved
I think the correct way to do this would be to But honestly this feels a bit over-engineered and could get complex (e.g. what about the cached queries that explicitely look at the trash/deleted items, we'll need to exclude them). So I would just advocate for doing a forced refetch of the list view query... @lucasbordeau what do you think? |
@FelixMalfait, does that mean we would not do optimistic updates for deletions, ignore caches, but just fetch it again from the server as if it were an initial rendering? Also, could you help me understand any potential issues my fix would pose? |
Hey, no we would keep the optimistic updates but still ask for a refetch for the list view. You can look for refetchQueries in the codebase to see how it's done already :) I'm just thinking we will also introduce #8345 soon which will make it even more useful to refetch everything from the server side (we're never going to implement logic like "max of CreatedAt" on the client side, so it makes sense to let the server deal with that and not do it optimistically) |
Solutions I'm thinking about :
Refetching list queries would trigger too many re-renders on tables and boards, we should separate concerns even if choosing a refetch query strategy. |
Discussed with @lucasbordeau: we should separate fetching aggregates into a separate request and refetch the aggregate query only (while still triggering the optimistic effect for rows/records) |
Thanks @FelixMalfait . It might not be a smart question. But do we already have an API for fetching aggregates, or should we build a new API for that? |
@khuddite I'm closing this PR because we need to first write a proper issue to explain what we want with @FelixMalfait I'll keep you posted for the new issue if you want to work on it. |
Fixes #8228
Summary
Total counts on record index tables are updated upon record deletion
Solution
The optimistic update logic seemed a bit complicated to me, so I didn't understand everything in there. However, it seems
triggerUpdateRecordOptimisticEffect
should account for deletion as well as update since it's used for both. I ended up updatingtotalCount
in Apollo cache along withnextEdges
to make sure they are always in sync.I am not quite sure if that's the best way to handle it though. It seems to be solving the problem without impacting other parts of the app in my manual testing.