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

chore: workspace entity search endpoint #6272

Open
wants to merge 3 commits into
base: preview
Choose a base branch
from

Conversation

NarayanBavisetti
Copy link
Collaborator

@NarayanBavisetti NarayanBavisetti commented Dec 24, 2024

Description

this pull request optimizes the workspace and project-level search for mentioning a specific type.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Summary by CodeRabbit

Release Notes

  • New Features

    • Updated URL structure for the entity-search endpoint to simplify access.
    • Enhanced search functionality with additional filtering options based on project_id and issue_id.
    • Introduced searchEntity method in WorkspaceService for entity searches within workspaces.
  • Bug Fixes

    • Improved response structure for search results to align with new filtering capabilities.
  • Refactor

    • Transitioned from ProjectService to WorkspaceService across various components for entity searching.
  • Chores

    • Removed obsolete searchEntity method from ProjectService.

Copy link
Contributor

coderabbitai bot commented Dec 24, 2024

Walkthrough

This pull request introduces significant changes to the search functionality across the Plane application. The modifications primarily involve transitioning from a project-specific search approach to a workspace-level search mechanism. Key changes include updating URL routing configurations, modifying search endpoint logic, and refactoring service implementations to use WorkspaceService instead of ProjectService. The changes simplify the search entity process by removing project ID dependencies and introducing more flexible search parameters.

Changes

File Change Summary
apiserver/plane/app/urls/search.py Updated URL routing for entity search, removing project ID from path
apiserver/plane/app/views/search/base.py Modified SearchEndpoint to handle project_id and issue_id query parameters
packages/types/src/search.d.ts Added optional project_id and team_id to search request payload type
web/core/components/*/ Replaced ProjectService with WorkspaceService in multiple editor and issue-related components
web/core/services/project/project.service.ts Removed searchEntity method
web/core/services/workspace.service.ts Added new searchEntity method for workspace-level searches

Sequence Diagram

sequenceDiagram
    participant Client
    participant WorkspaceService
    participant SearchEndpoint
    participant Database

    Client->>WorkspaceService: Request entity search
    WorkspaceService->>SearchEndpoint: Forward search parameters
    SearchEndpoint->>Database: Query entities with filters
    Database-->>SearchEndpoint: Return matching entities
    SearchEndpoint-->>WorkspaceService: Return search results
    WorkspaceService-->>Client: Provide search results
Loading

Possibly related PRs

Suggested labels

⚙️backend, 🧹chore, 🛠️refactor

Suggested reviewers

  • SatishGandham
  • pablohashescobar

Poem

🐰 A Rabbit's Search Ballad 🔍

Through workspaces wide and queries bright,
Our search now dances with delight!
No project walls can hold us back,
We hop and skip along the track.
Flexibility is our new art! 🚀

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@NarayanBavisetti NarayanBavisetti marked this pull request as ready for review December 24, 2024 14:06
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: 1

🧹 Nitpick comments (4)
apiserver/plane/app/views/search/base.py (3)

256-260: Consider splitting large logic into smaller helper methods.
The get method in SearchEndpoint is quite expansive and handles multiple query types. Splitting it into smaller, single-purpose methods (e.g., dedicated user_mention search, project search, etc.) could improve code readability and facilitate easier testing.


352-387: Consider indexing frequently queried fields.
Fields such as "name", "sequence_id", and "project__identifier" are frequently used in search conditions. Adding database indexes on these columns, if not already present, may improve performance for large datasets.


388-439: Add pagination or scrolling for large result sets.
While you slice results by [:count] in some query types, consider implementing more robust pagination for large cycles or user mentions to optimize performance and user experience.

web/core/components/issues/issue-modal/components/description-editor.tsx (1)

52-52: Ensure proper error handling and a single Instance
Using a dedicated workspaceService instance is straightforward. However, consider whether a single service instance should be shared globally or instantiated here, especially if additional cleanup is required in more complex scenarios.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ea78c2b and ebf9490.

📒 Files selected for processing (10)
  • apiserver/plane/app/urls/search.py (1 hunks)
  • apiserver/plane/app/views/search/base.py (2 hunks)
  • packages/types/src/search.d.ts (1 hunks)
  • web/core/components/editor/lite-text-editor/lite-text-editor.tsx (2 hunks)
  • web/core/components/inbox/modals/create-modal/issue-description.tsx (2 hunks)
  • web/core/components/issues/description-input.tsx (2 hunks)
  • web/core/components/issues/issue-modal/components/description-editor.tsx (3 hunks)
  • web/core/components/pages/editor/editor-body.tsx (2 hunks)
  • web/core/services/project/project.service.ts (1 hunks)
  • web/core/services/workspace.service.ts (2 hunks)
🔇 Additional comments (18)
apiserver/plane/app/views/search/base.py (3)

37-37: Confirmed usage of WorkspaceMember.
This import is newly referenced in the SearchEndpoint logic below, ensuring that workspace-level memberships can be queried. The addition looks correct given the broader changes related to searching by workspace context.


261-328: Validate role-based logic for user mentions.
Here, the query condition enforces role__gt=10, presumably limiting mentionable users to certain roles. If that threshold changes in the future, consider centralizing role checks in dedicated utilities or constants to avoid magic numbers scattered throughout the codebase.


330-351: Ensure consistent search filtering for Projects.
The logic here permits searching for archived/inactive projects only if project_projectmember__is_active=True is missing. Verify that the final results indeed exclude archived projects as intended, and ensure that partial or fuzzy matches align with business requirements.

apiserver/plane/app/urls/search.py (1)

19-19: URL routing for entity-search simplified.
The new endpoint path "workspaces/<str:slug>/entity-search/" aligns with workspace-centric lookups, removing the requirement for a project ID in the URL. Ensure that legacy clients using the old route are updated or gracefully handled.

packages/types/src/search.d.ts (1)

79-82: Enhanced payload flexibility with optional IDs.
Including optional project_id and team_id fosters more granular search contexts. Confirm that existing consumers of TSearchEntityRequestPayload handle these newly optional fields gracefully (e.g., defaulting to workspace-level searches if they are absent).

web/core/components/inbox/modals/create-modal/issue-description.tsx (2)

27-27: Switched to WorkspaceService.
Using workspaceService reflects the move toward workspace-level queries. This is consistent with the updated /entity-search/ endpoint. Confirm that all old references to ProjectService are removed or updated to prevent confusion.


79-82: Confirm searchEntity payload correctness.
Here, you spread payload and inject project_id: projectId. Verify that the front-end or the server handles empty or null projectId cases correctly, ensuring fallback to workspace-wide searching when necessary.

web/core/components/editor/lite-text-editor/lite-text-editor.tsx (2)

17-19: Consistent usage of WorkspaceService.
The replacement of ProjectService with WorkspaceService aligns with the broader shift to workspace-based queries throughout the codebase. This looks consistent with the changes in the service layer.


58-61: Parameterize project ID in mentions search.
Passing the project_id within searchEntity ensures that mention queries remain project-specific when needed. Same as before, verify that the cases with no project_id fallback gracefully to workspace-level mention searches if that’s intended.

web/core/services/project/project.service.ts (1)

1-1: Confirm removal of searchEntity references.

It appears that imports related to searchEntity (e.g., TSearchEntityRequestPayload and TSearchResponse) have been removed. Ensure that all references to searchEntity are no longer required in this service and that consumers of this functionality have been successfully migrated to WorkspaceService.

web/core/components/issues/description-input.tsx (2)

19-23: Use consistent service instantiations.

You’ve introduced WorkspaceService here, in line with the refactor away from ProjectService. This replacement is structurally sound and aligns with the new workspace-centric approach.


125-128: Ensure search parameters are correct.

The searchMentionCallback now calls workspaceService.searchEntity with an added project_id field. This is correct for preserving project context while still enabling workspace-level searches. Verify that any client code relying on project-specific searching is updated accordingly.

web/core/components/pages/editor/editor-body.tsx (2)

33-34: Instantiation of WorkspaceService instead of ProjectService.

Switching from ProjectService to WorkspaceService is consistent with the new entity-search flow. No issues noted in logic or syntax.

Also applies to: 40-40


67-70: Retain project context in workspace-level searches.

Passing project_id within the search payload helps preserve context for project-scoped results, even though the top-level search is done at the workspace. This approach appears correct for maintaining backwards compatibility with project-based references.

web/core/services/workspace.service.ts (2)

15-16: Added imports for new entity search types.

Imports of TSearchResponse and TSearchEntityRequestPayload look correct, matching the new method’s parameters and response types.


283-294: New workspace-level search entity method.

The searchEntity method cleanly supports optional project and team context. The logic to join array elements of query_type is straightforward and performs a valid GET request. This implementation aligns well with the rest of the refactor.

web/core/components/issues/issue-modal/components/description-editor.tsx (2)

26-27: Seamless transition from ProjectService to WorkspaceService
The new import for WorkspaceService provides a clear shift to workspace-centric operations, aligning well with the PR’s objective.


195-198: Validate empty project IDs
When projectId is null, it’s converted to an empty string here. Confirm that searchEntity can gracefully handle empty project IDs and returns correct results.

Comment on lines +499 to +708
),
When(
start_date__gt=timezone.now(),
then=Value("UPCOMING"),
),
When(
end_date__lt=timezone.now(), then=Value("COMPLETED")
),
When(
Q(start_date__isnull=True)
& Q(end_date__isnull=True),
then=Value("DRAFT"),
),
default=Value("DRAFT"),
output_field=CharField(),
)
)
.order_by("-created_at")
.distinct()
.values(
"name",
"id",
"project_id",
"project__identifier",
"status",
"workspace__slug",
)[:count]
)
.order_by("-created_at")
.distinct()
.values(
"name", "id", "logo_props", "projects__id", "workspace__slug"
)[:count]
)
response_data["page"] = list(pages)
response_data["cycle"] = list(cycles)

else:
return Response(
{"error": f"Invalid query type: {query_type}"},
status=status.HTTP_400_BAD_REQUEST,
)
elif query_type == "module":
fields = ["name"]
q = Q()

return Response(response_data, status=status.HTTP_200_OK)
if query:
for field in fields:
q |= Q(**{f"{field}__icontains": query})

modules = (
Module.objects.filter(
q,
project__project_projectmember__member=self.request.user,
project__project_projectmember__is_active=True,
workspace__slug=slug,
)
.order_by("-created_at")
.distinct()
.values(
"name",
"id",
"project_id",
"project__identifier",
"status",
"workspace__slug",
)[:count]
)
response_data["module"] = list(modules)

elif query_type == "page":
fields = ["name"]
q = Q()

if query:
for field in fields:
q |= Q(**{f"{field}__icontains": query})

pages = (
Page.objects.filter(
q,
projects__project_projectmember__member=self.request.user,
projects__project_projectmember__is_active=True,
workspace__slug=slug,
access=0,
is_global=True,
)
.order_by("-created_at")
.distinct()
.values(
"name",
"id",
"logo_props",
"projects__id",
"workspace__slug",
)[:count]
)
response_data["page"] = list(pages)
return Response(response_data, status=status.HTTP_200_OK)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid duplicate blocks for project_id vs. workspace-level searches.
Much of the logic below duplicates the queries from the earlier if project_id: block. Consider refactoring to unify the search code paths, parameterizing them as needed so that only filter specifics differ. This will reduce maintenance costs and potential inconsistencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants