-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Refetch aggregate queries on record creation/update/deletion of record #8885
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 adds functionality to refetch aggregate queries after record operations, since aggregate values cannot be computed optimistically in the cache like regular queries.
- Added new
useRefetchAggregateQueries
hook in/packages/twenty-front/src/modules/object-record/hooks/useRefetchAggregateQueries.ts
to centralize aggregate query refetching logic - Integrated refetch calls after mutations in record operation hooks (create/update/delete) to keep aggregate data in sync
- Potential issue:
useUpdateOneRecord.ts
has duplicate refetch calls in both mutation update callback and completion - Added feature flag
IS_AGGREGATE_QUERY_ENABLED
to control aggregate functionality with proper fallbacks - Improved error handling needed in
useRefetchAggregateQueries
for failed refetch operations
13 file(s) reviewed, 12 comment(s)
Edit PR Review Bot Settings | Greptile
await refetchAggregateQueries(); | ||
return createdObjects.data?.[mutationResponseField] ?? []; |
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.
style: consider wrapping refetch in try/catch to handle potential refetch failures gracefully
|
||
await refetchAggregateQueries(); |
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.
logic: refetchAggregateQueries could fail silently here - consider handling errors or at least logging them
packages/twenty-front/src/modules/object-record/hooks/useDeleteManyRecords.ts
Show resolved
Hide resolved
@@ -126,6 +131,7 @@ export const useDeleteOneRecord = ({ | |||
throw error; | |||
}); | |||
|
|||
await refetchAggregateQueries(); |
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.
style: refetchAggregateQueries() should be wrapped in a try/catch to handle potential refetch failures gracefully
export const useRefetchAggregateQueries = ({ | ||
objectMetadataNamePlural, | ||
}: { | ||
objectMetadataNamePlural: string; |
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.
logic: objectMetadataNamePlural should be validated - getAggregateQueryName will throw if this is empty
packages/twenty-front/src/modules/object-record/hooks/useUpdateOneRecord.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/object-record/hooks/useUpdateOneRecord.ts
Outdated
Show resolved
Hide resolved
...ard/record-board-column/components/RecordBoardColumnHeaderAggregateDropdownFieldsContent.tsx
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/object-record/utils/getAggregateQueryName.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/object-record/utils/getAggregateQueryName.ts
Outdated
Show resolved
Hide resolved
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.
LGTM, could you add tests on your utils and hooks?
- generatedAggregateQuery.ts + useAggregateManyQuery.ts
- getAggregateQueryName.ts
@@ -141,6 +146,7 @@ export const useCreateManyRecords = < | |||
throw error; | |||
}); | |||
|
|||
await refetchAggregateQueries(); |
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.
this will seek to refetch aggregate queries even if there were no AggregateQueries performed before (like on table view for instance). I think it's ok but it does trigger a warning (yellow) in the console.
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.
@charlesBochet fyi
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.
Also, not related to this PR but we have inconsitent naming:
useAggregateManyRecords vs generateAggregateQuery.ts
I feel the many is implicit and there is no point having it: useAggregateManyRecords => useAggregateRecords
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.
LGTM
Nice |
Closes #8755.
Refetching the aggregate queries on an object following creation, update, deletion of a record.