-
Notifications
You must be signed in to change notification settings - Fork 557
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
Query performance operators #4875
Conversation
WalkthroughThe changes introduce new classes for managing query performance within an operator framework, specifically Changes
Possibly related PRs
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (6)
app/packages/state/src/hooks/useQueryPerformance.ts (2)
1-9
: Consider naming the exported function for better maintainabilityWhile exporting a default function is valid, naming it (e.g.,
useQueryPerformance
) would improve code readability and make it easier to debug or reference in other parts of the codebase.Consider updating the export as follows:
-export default function () { +export default function useQueryPerformance() {
18-32
: LGTM: Theenable
function is well-implemented with a minor suggestionThe
enable
function is correctly implemented usinguseRecoilCallback
. It handles the optionalthreshold
parameter well and has a good fallback mechanism. The asynchronous operations are properly managed.Consider adding a type annotation for the
threshold
parameter to improve type safety:- async (threshold?: number) => { + async (threshold?: number | null) => {This change allows for explicitly setting the threshold to
null
if needed, matching the behavior of thedisable
function.app/packages/operators/src/operators.ts (2)
94-94
: LGTM! Consider adding documentation.The addition of the
queryPerformance
property to theRawContext
type is appropriate. It's correctly defined as an optional boolean, which aligns well with its purpose as a performance tracking flag.Consider adding a brief comment explaining the purpose of this property and when it should be set.
140-142
: LGTM! Consider a minor optimization.The
queryPerformance
getter is well-implemented, following the pattern of other getters in the class and ensuring type consistency by usingBoolean()
.For a slight optimization, you could use the logical OR operator instead of
Boolean()
:- return Boolean(this._currentContext.queryPerformance); + return this._currentContext.queryPerformance || false;This achieves the same result but avoids the function call to
Boolean()
.app/packages/operators/src/built-in-operators.ts (2)
1316-1332
: LGTM! Consider adding a resolveInput method for consistency.The
DisableQueryPerformance
class is well-implemented and follows the structure of other operator classes. It correctly extends theOperator
class, sets the_builtIn
property, and implements the required methods.For consistency with other operator classes, consider adding a
resolveInput
method, even if it returns an empty object:async resolveInput(): Promise<types.Property> { return new types.Property(new types.Object()); }This addition would make the class structure more uniform with other operators in the file.
1334-1350
: LGTM! Consider adding a resolveInput method for consistency.The
EnableQueryPerformance
class is well-implemented and follows the structure of other operator classes. It correctly extends theOperator
class, sets the_builtIn
property, and implements the required methods.As with the
DisableQueryPerformance
class, consider adding aresolveInput
method for consistency:async resolveInput(): Promise<types.Property> { return new types.Property(new types.Object()); }This addition would make the class structure more uniform with other operators in the file.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (6)
- app/packages/operators/src/built-in-operators.ts (2 hunks)
- app/packages/operators/src/operators.ts (4 hunks)
- app/packages/operators/src/state.ts (5 hunks)
- app/packages/state/src/hooks/index.ts (1 hunks)
- app/packages/state/src/hooks/useQueryPerformance.ts (1 hunks)
- fiftyone/operators/executor.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
app/packages/operators/src/built-in-operators.ts (1)
Pattern
**/*.{ts,tsx}
: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.app/packages/operators/src/operators.ts (1)
Pattern
**/*.{ts,tsx}
: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.app/packages/operators/src/state.ts (1)
Pattern
**/*.{ts,tsx}
: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.app/packages/state/src/hooks/index.ts (1)
Pattern
**/*.{ts,tsx}
: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.app/packages/state/src/hooks/useQueryPerformance.ts (1)
Pattern
**/*.{ts,tsx}
: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.
🔇 Additional comments (10)
app/packages/state/src/hooks/useQueryPerformance.ts (3)
10-16
: LGTM: Thedisable
function is well-implementedThe
disable
function correctly usesuseRecoilCallback
to set thelightningThreshold
state tonull
. The empty dependency array ensures optimal performance by creating the callback only once.
34-41
: LGTM: Effective use ofuseMemo
for performance optimizationThe hook's return value is correctly memoized using
useMemo
. This optimization prevents unnecessary re-renders by ensuring the returned object is only recreated when either thedisable
orenable
function changes. The dependency array is correctly specified.
1-41
: Overall: Well-implemented custom hook for query performance managementThe
useQueryPerformance
hook is thoughtfully designed and implemented. It effectively leverages Recoil for state management and follows React best practices. The hook provides clear and concise functions for enabling and disabling the query performance threshold, with good fallback mechanisms and performance optimizations.Great job on creating a reusable and efficient solution for managing query performance in the application!
app/packages/state/src/hooks/index.ts (1)
27-27
: LGTM: New hook export aligns with PR objectivesThe addition of the
useQueryPerformance
hook export is consistent with the existing code structure and follows the established pattern in this file. This change directly supports the PR's objective of introducing query performance operators.app/packages/operators/src/operators.ts (1)
714-714
: LGTM! Verify server-side handling.The addition of
query_performance
to the payload is correct and consistent with the existing code structure.Ensure that the server-side code is updated to handle this new property. Run the following script to check for server-side changes:
app/packages/operators/src/built-in-operators.ts (2)
1401-1402
: LGTM! New operators correctly registered.The
DisableQueryPerformance
andEnableQueryPerformance
operators are correctly registered in theregisterBuiltInOperators
function. These additions are consistent with the registration of other operators in the function.
Line range hint
1316-1402
: Summary: New query performance operators successfully implementedThe changes introduce two new operator classes,
DisableQueryPerformance
andEnableQueryPerformance
, which extend the functionality of the application to control query performance. These classes are well-implemented, following the existing patterns in the codebase, and are correctly registered in theregisterBuiltInOperators
function.The new operators will allow users to enable or disable query performance features, potentially improving the flexibility and control over the application's behavior.
Consider adding
resolveInput
methods to both new classes for complete consistency with other operators, but this is a minor suggestion and doesn't affect the functionality of the implementation.Overall, these changes are well-structured and integrate seamlessly with the existing codebase.
fiftyone/operators/executor.py (1)
716-720
: LGTM: New property added for query performance.The new
query_performance
property has been added to theExecutionContext
class. This property allows checking whether query performance is enabled for the current execution context.A few observations:
- The property is implemented as a getter method, which is appropriate for this use case.
- It correctly retrieves the value from the
request_params
dictionary, defaulting toNone
if the key is not present.- The property is well-documented with a clear and concise docstring.
This addition enhances the functionality of the
ExecutionContext
class by providing a way to access query performance settings, which aligns with the PR objectives of introducing query performance operators.app/packages/operators/src/state.ts (2)
Line range hint
97-109
: Verify thatqueryPerformance
is correctly typed and integrated.The
queryPerformance
variable is derived from checking iffos.lightningThreshold
is a number and is added to the global context. Ensure that all relevant TypeScript interfaces or types includequeryPerformance
to maintain type safety across the application.
Line range hint
150-184
: EnsurequeryPerformance
is properly handled inExecutionContext
.In the
useExecutionContext
function,queryPerformance
is destructured fromcurCtx
, passed intoExecutionContext
, and included in the dependency array. Verify that theExecutionContext
class and any related type definitions are updated to accept and correctly utilizequeryPerformance
.
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.
Functionality works 🚀 🙇♂️
What changes are proposed in this pull request?
Adds
enable_query_performance
anddisable_query_performance
operatorsScreen.Recording.2024-10-01.at.4.14.58.PM.mov
How is this patch tested? If it is not, please explain why.
todo
What areas of FiftyOne does this PR affect?
fiftyone
Python library changesSummary by CodeRabbit
New Features
Bug Fixes
Documentation
useQueryPerformance
hook.Refactor