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

Query performance operators #4875

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions app/packages/operators/src/built-in-operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@
unlisted: true,
});
}
useHooks(ctx: ExecutionContext): {} {

Check warning on line 815 in app/packages/operators/src/built-in-operators.ts

View workflow job for this annotation

GitHub Actions / lint / eslint

'ctx' is defined but never used. Allowed unused args must match /^_/u
return { updatePanelState: useUpdatePanelStatePartial() };
}
async execute(ctx: ExecutionContext): Promise<void> {
Expand Down Expand Up @@ -1313,6 +1313,42 @@
}
}

export class DisableQueryPerformance extends Operator {
_builtIn = true;
get config(): OperatorConfig {
return new OperatorConfig({
name: "disable_query_performance",
label: "Disable query performance",
});
}

useHooks() {
const { disable } = fos.useQueryPerformance();
return { disable };
}
async execute({ hooks }: ExecutionContext) {
hooks.disable();
}
}

export class EnableQueryPerformance extends Operator {
_builtIn = true;
get config(): OperatorConfig {
return new OperatorConfig({
name: "enable_query_performance",
label: "Enable query performance",
});
}

useHooks() {
const { enable } = fos.useQueryPerformance();
return { enable };
}
async execute({ hooks }: ExecutionContext) {
hooks.enable();
}
}

export function registerBuiltInOperators() {
try {
_registerBuiltInOperator(CopyViewAsJSON);
Expand Down Expand Up @@ -1362,6 +1398,8 @@
_registerBuiltInOperator(SetGroupSlice);
_registerBuiltInOperator(SetPlayheadState);
_registerBuiltInOperator(SetFrameNumber);
_registerBuiltInOperator(DisableQueryPerformance);
_registerBuiltInOperator(EnableQueryPerformance);
} catch (e) {
console.error("Error registering built-in operators");
console.error(e);
Expand Down
8 changes: 7 additions & 1 deletion app/packages/operators/src/operators.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AnalyticsInfo, usingAnalytics } from "@fiftyone/analytics";
import { getFetchFunction, isNullish, ServerError } from "@fiftyone/utilities";
import { ServerError, getFetchFunction, isNullish } from "@fiftyone/utilities";
import { CallbackInterface } from "recoil";
import { QueueItemStatus } from "./constants";
import * as types from "./types";
Expand Down Expand Up @@ -91,6 +91,7 @@ export type RawContext = {
scope: string;
};
groupSlice: string;
queryPerformance?: boolean;
};

export class ExecutionContext {
Expand Down Expand Up @@ -136,6 +137,10 @@ export class ExecutionContext {
public get groupSlice(): any {
return this._currentContext.groupSlice;
}
public get queryPerformance(): boolean {
return Boolean(this._currentContext.queryPerformance);
}

getCurrentPanelId(): string | null {
return this.params.panel_id || this.currentPanel?.id || null;
}
Expand Down Expand Up @@ -706,6 +711,7 @@ export async function executeOperatorWithContext(
view: currentContext.view,
view_name: currentContext.viewName,
group_slice: currentContext.groupSlice,
query_performance: currentContext.queryPerformance,
}
);
result = serverResult.result;
Expand Down
5 changes: 5 additions & 0 deletions app/packages/operators/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const globalContextSelector = selector({
const viewName = get(fos.viewName);
const extendedSelection = get(fos.extendedSelection);
const groupSlice = get(fos.groupSlice);
const queryPerformance = typeof get(fos.lightningThreshold) === "number";

return {
datasetName,
Expand All @@ -105,6 +106,7 @@ const globalContextSelector = selector({
viewName,
extendedSelection,
groupSlice,
queryPerformance,
};
},
});
Expand Down Expand Up @@ -145,6 +147,7 @@ const useExecutionContext = (operatorName, hooks = {}) => {
viewName,
extendedSelection,
groupSlice,
queryPerformance,
} = curCtx;
const [analyticsInfo] = useAnalyticsInfo();
const ctx = useMemo(() => {
Expand All @@ -162,6 +165,7 @@ const useExecutionContext = (operatorName, hooks = {}) => {
extendedSelection,
analyticsInfo,
groupSlice,
queryPerformance,
},
hooks
);
Expand All @@ -177,6 +181,7 @@ const useExecutionContext = (operatorName, hooks = {}) => {
viewName,
currentSample,
groupSlice,
queryPerformance,
]);

return ctx;
Expand Down
1 change: 1 addition & 0 deletions app/packages/state/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export { default as useLookerStore } from "./useLookerStore";
export { default as useNotification } from "./useNotification";
export * from "./useOnSelectLabel";
export { default as usePanel } from "./usePanel";
export { default as useQueryPerformance } from "./useQueryPerformance";
export { default as useRefresh } from "./useRefresh";
export { default as useReset } from "./useReset";
export { default as useResetExtendedSelection } from "./useResetExtendedSelection";
Expand Down
41 changes: 41 additions & 0 deletions app/packages/state/src/hooks/useQueryPerformance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { useMemo } from "react";
import { useRecoilCallback } from "recoil";
import {
datasetSampleCount,
lightningThreshold,
lightningThresholdConfig,
} from "../recoil";

export default function () {
const disable = useRecoilCallback(
({ set }) =>
() => {
set(lightningThreshold, null);
},
[]
);

const enable = useRecoilCallback(
({ set, snapshot }) =>
async (threshold?: number) => {
let setting = threshold;

if (setting === undefined) {
setting =
(await snapshot.getPromise(lightningThresholdConfig)) ??
(await snapshot.getPromise(datasetSampleCount));
}

set(lightningThreshold, setting);
},
[]
);

return useMemo(
() => ({
disable,
enable,
}),
[disable, enable]
);
}
5 changes: 5 additions & 0 deletions fiftyone/operators/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,11 @@ def group_slice(self):
"""The current group slice of the view (if any)."""
return self.request_params.get("group_slice", None)

@property
def query_performance(self):
"""Whether query performance is enabled."""
return self.request_params.get("query_performance", None)

def prompt(
self,
operator_uri,
Expand Down
Loading