-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
base: preview
Are you sure you want to change the base?
Conversation
WalkthroughThis 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 Changes
Sequence DiagramsequenceDiagram
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
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Tip CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command 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
CodeRabbit Configuration File (
|
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: 1
🧹 Nitpick comments (4)
apiserver/plane/app/views/search/base.py (3)
256-260
: Consider splitting large logic into smaller helper methods.
Theget
method inSearchEndpoint
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 dedicatedworkspaceService
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
📒 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.
), | ||
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) |
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.
🛠️ 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.
Description
this pull request optimizes the workspace and project-level search for mentioning a specific type.
Type of Change
Summary by CodeRabbit
Release Notes
New Features
entity-search
endpoint to simplify access.project_id
andissue_id
.searchEntity
method inWorkspaceService
for entity searches within workspaces.Bug Fixes
Refactor
ProjectService
toWorkspaceService
across various components for entity searching.Chores
searchEntity
method fromProjectService
.