fix: search endpoint to return distint results (#566)

Co-authored-by: Vamsi Kurama <vamsi.kurama@gmail.com>
This commit is contained in:
pablohashescobar 2023-03-29 00:23:35 +05:30 committed by GitHub
parent 05e9c0f76f
commit 628591854d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,7 +26,7 @@ class GlobalSearchEndpoint(BaseAPIView):
q |= Q(**{f"{field}__icontains": query}) q |= Q(**{f"{field}__icontains": query})
return Workspace.objects.filter( return Workspace.objects.filter(
q, workspace_member__member=self.request.user q, workspace_member__member=self.request.user
).values("name", "id", "slug") ).distinct().values("name", "id", "slug")
def filter_projects(self, query, slug, project_id): def filter_projects(self, query, slug, project_id):
fields = ["name"] fields = ["name"]
@ -37,7 +37,7 @@ class GlobalSearchEndpoint(BaseAPIView):
q, q,
Q(project_projectmember__member=self.request.user) | Q(network=2), Q(project_projectmember__member=self.request.user) | Q(network=2),
workspace__slug=slug, workspace__slug=slug,
).values("name", "id", "identifier", "workspace__slug") ).distinct().values("name", "id", "identifier", "workspace__slug")
def filter_issues(self, query, slug, project_id): def filter_issues(self, query, slug, project_id):
fields = ["name", "sequence_id"] fields = ["name", "sequence_id"]
@ -54,7 +54,7 @@ class GlobalSearchEndpoint(BaseAPIView):
project__project_projectmember__member=self.request.user, project__project_projectmember__member=self.request.user,
workspace__slug=slug, workspace__slug=slug,
project_id=project_id, project_id=project_id,
).values( ).distinct().values(
"name", "name",
"id", "id",
"sequence_id", "sequence_id",
@ -73,7 +73,7 @@ class GlobalSearchEndpoint(BaseAPIView):
project__project_projectmember__member=self.request.user, project__project_projectmember__member=self.request.user,
workspace__slug=slug, workspace__slug=slug,
project_id=project_id, project_id=project_id,
).values( ).distinct().values(
"name", "name",
"id", "id",
"project_id", "project_id",
@ -90,7 +90,7 @@ class GlobalSearchEndpoint(BaseAPIView):
project__project_projectmember__member=self.request.user, project__project_projectmember__member=self.request.user,
workspace__slug=slug, workspace__slug=slug,
project_id=project_id, project_id=project_id,
).values( ).distinct().values(
"name", "name",
"id", "id",
"project_id", "project_id",
@ -107,7 +107,7 @@ class GlobalSearchEndpoint(BaseAPIView):
project__project_projectmember__member=self.request.user, project__project_projectmember__member=self.request.user,
workspace__slug=slug, workspace__slug=slug,
project_id=project_id, project_id=project_id,
).values( ).distinct().values(
"name", "name",
"id", "id",
"project_id", "project_id",
@ -124,7 +124,7 @@ class GlobalSearchEndpoint(BaseAPIView):
project__project_projectmember__member=self.request.user, project__project_projectmember__member=self.request.user,
workspace__slug=slug, workspace__slug=slug,
project_id=project_id, project_id=project_id,
).values( ).distinct().values(
"name", "name",
"id", "id",
"project_id", "project_id",