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

Allow SelectGroupSlices for QP #5428

Merged
merged 3 commits into from
Jan 27, 2025
Merged

Allow SelectGroupSlices for QP #5428

merged 3 commits into from
Jan 27, 2025

Conversation

benjaminpkane
Copy link
Contributor

@benjaminpkane benjaminpkane commented Jan 23, 2025

What changes are proposed in this pull request?

Allows QP when a SelectGroupSlices stage is present

Screenshot 2025-01-23 at 5 59 01 PM
from collections import defaultdict
from PIL import Image, ImageDraw, ImageFont

import fiftyone as fo


WHITE = "white"
BLACK = "black"
DIR = "/Users/ben/data/numbers"
FONT = ImageFont.truetype("Palanquin-Regular.ttf", 51)
FONT_COLOR = (255, 109, 5)
SIZE = (510, 510)
W, H = SIZE


def create_index_image(index, background):
    image = Image.new("RGB", (SIZE[0], SIZE[1]), background)
    draw = ImageDraw.Draw(image)
    _, _, w, h = draw.textbbox((0, 0), str(index), font=FONT)
    draw.text(
        ((W - w) / 2, (H - h) / 2), str(index), font=FONT, fill=FONT_COLOR
    )
    return image


data = defaultdict(dict)

for i in range(1, 511):
    for background in (BLACK, WHITE):
        filepath = f"{DIR}/{i}-{background}.png"
        create_index_image(i, background).save(filepath, "PNG")
        data[i][background] = filepath

try:
    fo.delete_dataset("numbers-groups")
except:
    pass

dataset = fo.Dataset("numbers-groups")
dataset.persistent = True

samples = []
for index, backgrounds in data.items():
    group = fo.Group()
    for background, filepath in backgrounds.items():
        samples.append(
            fo.Sample(
                filepath=filepath, index=i, group=group.element(background)
            )
        )

dataset.add_samples(samples)

How is this patch tested? If it is not, please explain why.

Selector test

Release Notes

  • Added Query Performance support for SelectGroupSlices views

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • Tests

    • Added new test case for query performance selectors
    • Expanded test coverage for query performance functionality
  • New Features

    • Introduced new selectors for query performance settings
    • Added logic to evaluate query performance based on view stages
  • Refactor

    • Updated query performance selector implementation
    • Relocated and modified query performance store configuration

@benjaminpkane benjaminpkane added enhancement Code enhancement app Issues related to App features labels Jan 23, 2025
@benjaminpkane benjaminpkane self-assigned this Jan 23, 2025
Copy link
Contributor

coderabbitai bot commented Jan 23, 2025

Walkthrough

The pull request introduces enhancements to the query performance functionality in the Recoil state management module. The changes focus on improving the queryPerformance.ts file by adding new selectors like isQueryPerformantView and queryPerformanceSetting. A corresponding test case is added to queryPerformance.test.ts to validate the new functionality, expanding the test coverage for query performance-related logic.

Changes

File Change Summary
app/packages/state/src/recoil/queryPerformance.test.ts Added new test case "resolves query performant views" with TestSelector import
app/packages/state/src/recoil/queryPerformance.ts - Added SELECT_GROUP_SLICES constant
- Introduced VALID_QP_STAGES set
- Created new selectors: isQueryPerformantView and queryPerformanceSetting
- Modified queryPerformance selector logic
- Relocated queryPerformanceStore atomFamily

Sequence Diagram

sequenceDiagram
    participant User
    participant QueryPerformance
    participant QueryPerformanceStore
    
    User->>QueryPerformance: Request performance check
    QueryPerformance->>QueryPerformance: Check valid stages
    QueryPerformance->>QueryPerformanceStore: Retrieve/Set performance setting
    QueryPerformanceStore-->>QueryPerformance: Return performance configuration
    QueryPerformance-->>User: Provide performance status
Loading

Possibly related PRs

Suggested reviewers

  • brimoor
  • sashankaryal

Poem

🐰 Query performance, oh so bright,
Selectors dancing with delight,
Stages checked, settings clear,
Efficiency now draws near,
Code rabbit hops with pure glee! 🚀

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (2)
app/packages/state/src/recoil/queryPerformance.ts (1)

22-24: Consider centralizing stage constants for maintainability

Defining SELECT_GROUP_SLICES and VALID_QP_STAGES within this file may lead to duplication if these constants are used elsewhere. Consider importing them from a shared constants module to improve maintainability and ensure consistency across the codebase.

app/packages/state/src/recoil/queryPerformance.test.ts (1)

31-33: Simplify type casting in test setup

Instead of casting queryPerformance.isQueryPerformantView to unknown before assigning to TestSelector, consider direct casting to improve readability:

-const test = <TestSelector<typeof queryPerformance.isQueryPerformantView>>(
-  (<unknown>queryPerformance.isQueryPerformantView)
-);
+const test = queryPerformance.isQueryPerformantView as TestSelector<typeof queryPerformance.isQueryPerformantView>;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 67bdf7e and c69a3a7.

📒 Files selected for processing (2)
  • app/packages/state/src/recoil/queryPerformance.test.ts (2 hunks)
  • app/packages/state/src/recoil/queryPerformance.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
app/packages/state/src/recoil/queryPerformance.test.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/recoil/queryPerformance.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.

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build / build
  • GitHub Check: test / test-app
  • GitHub Check: lint / eslint
🔇 Additional comments (7)
app/packages/state/src/recoil/queryPerformance.ts (5)

194-208: LGTM: Correct implementation of isQueryPerformantView selector

The isQueryPerformantView selector accurately assesses whether the current view stages are valid for query performance optimizations based on the defined VALID_QP_STAGES.


223-224: LGTM: Updated logic in queryPerformance selector

The queryPerformance selector now appropriately combines queryPerformanceSetting and isQueryPerformantView to determine if query performance should be enabled.


225-231: Ensure correct handling of DefaultValue in set method

Confirm that the value instanceof DefaultValue check correctly resets the queryPerformanceStore atom family to its default state when necessary.


Line range hint 233-254: LGTM: Addition of queryPerformanceSetting selector

The queryPerformanceSetting selector effectively manages the query performance setting by considering the configuration, stored values, and default settings.


255-264: LGTM: Proper use of queryPerformanceStore atom family

The queryPerformanceStore atom family correctly utilizes browser storage effects to persist the query performance settings per dataset.

app/packages/state/src/recoil/queryPerformance.test.ts (2)

6-9: LGTM: Proper import of test types

The import of TestSelector and TestSelectorFamily types from the mocked recoil module enhances type safety in tests.


30-62: LGTM: Comprehensive test cases for isQueryPerformantView

The added test cases thoroughly verify the isQueryPerformantView selector's logic with various view configurations, ensuring robust functionality.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (2)
app/packages/state/src/recoil/queryPerformance.ts (2)

194-208: Consider extracting stage validation logic for better maintainability.

The selector logic is correct, but could be more maintainable by extracting the stage validation into a separate function.

Consider this refactor:

+const isValidQPStage = (stage: { _cls: string }) => VALID_QP_STAGES.has(stage._cls);
+
 export const isQueryPerformantView = selector({
   key: "isQueryPerformantView",
   get: ({ get }) => {
     const stages = get(view);
     if (!stages?.length) {
       return true;
     }

     if (stages.length === 1) {
-      return VALID_QP_STAGES.has(stages[0]._cls);
+      return isValidQPStage(stages[0]);
     }

     return false;
   },
 });

Line range hint 226-247: Consider adding explicit type annotations for better maintainability.

The selector logic is solid, but could benefit from explicit TypeScript types.

Consider this enhancement:

+type QueryPerformanceValue = boolean | undefined;
+
 export const queryPerformanceSetting = selector<boolean>({
   key: "queryPerformanceSetting",
-  get: ({ get }) => {
+  get: ({ get }): boolean => {
     if (!get(enableQueryPerformanceConfig)) {
       return false;
     }

-    const storedValue = get(queryPerformanceStore(get(datasetId)));
+    const storedValue: QueryPerformanceValue = get(queryPerformanceStore(get(datasetId)));
     if (storedValue !== undefined) {
       return storedValue;
     }

     return get(defaultQueryPerformanceConfig);
   },
-  set: ({ get, set }, value) => {
+  set: ({ get, set }, value: boolean | DefaultValue): void => {
     set(
       queryPerformanceStore(get(datasetId)),
       value instanceof DefaultValue ? undefined : value
     );
   },
 });
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c69a3a7 and aa6e84b.

📒 Files selected for processing (1)
  • app/packages/state/src/recoil/queryPerformance.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/state/src/recoil/queryPerformance.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 (3)
app/packages/state/src/recoil/queryPerformance.ts (3)

22-23: LGTM! Well-structured constants for QP stage validation.

The use of a Set for VALID_QP_STAGES provides efficient lookups, and the naming follows TypeScript conventions.


222-224: LGTM! Clean integration of QP stage validation.

The selector correctly combines the performance setting with stage validation, following Recoil best practices.


248-257: LGTM! Well-configured storage for query performance state.

The atomFamily correctly uses session storage with proper dataset isolation and value type configuration.

@benjaminpkane benjaminpkane merged commit d87fae5 into develop Jan 27, 2025
12 checks passed
@benjaminpkane benjaminpkane deleted the feat/is-qp branch January 27, 2025 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app Issues related to App features enhancement Code enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants