Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions backend/apps/github/api/internal/nodes/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
if TYPE_CHECKING:
from apps.owasp.api.internal.nodes.project import ProjectNode

MAX_LIMIT = 1000
RECENT_ISSUES_LIMIT = 5
RECENT_RELEASES_LIMIT = 5

Expand Down Expand Up @@ -69,6 +70,16 @@ def project(
@strawberry_django.field(prefetch_related=["milestones"])
def recent_milestones(self, root: Repository, limit: int = 5) -> list[MilestoneNode]:
"""Resolve recent milestones."""
try:
limit = int(limit)
except (TypeError, ValueError):
return []

if limit <= 0:
return []

limit = min(limit, MAX_LIMIT)

return root.recent_milestones.order_by("-created_at")[:limit]

@strawberry_django.field(prefetch_related=["releases"])
Expand Down
16 changes: 11 additions & 5 deletions backend/apps/github/api/internal/queries/milestone.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@ def recent_milestones(
id__in=Subquery(latest_milestone_per_author),
)

return (
milestones.order_by("-created_at")[:limit]
if (limit := min(limit, MAX_LIMIT)) > 0
else []
)
try:
limit = int(limit)
except (TypeError, ValueError):
return []

if limit <= 0:
return []

limit = min(limit, MAX_LIMIT)

return milestones.order_by("-created_at")[:limit]
32 changes: 22 additions & 10 deletions backend/apps/owasp/api/internal/nodes/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,17 @@ def health_metrics_list(
self, root: Project, limit: int = 30
) -> list[ProjectHealthMetricsNode]:
"""Resolve project health metrics."""
return (
root.health_metrics.order_by("nest_created_at")[:limit]
if (limit := min(limit, MAX_LIMIT)) > 0
else []
)
try:
limit = int(limit)
except (TypeError, ValueError):
return []

if limit <= 0:
return []

limit = min(limit, MAX_LIMIT)

return root.health_metrics.order_by("nest_created_at")[:limit]

@strawberry_django.field(prefetch_related=["health_metrics"])
def health_metrics_latest(self, root: Project) -> ProjectHealthMetricsNode | None:
Expand Down Expand Up @@ -87,6 +93,16 @@ def recent_issues(self, root: Project) -> list[IssueNode]:
@strawberry_django.field
def recent_milestones(self, root: Project, limit: int = 5) -> list[MilestoneNode]:
"""Resolve recent milestones."""
try:
limit = int(limit)
except (TypeError, ValueError):
return []

if limit <= 0:
return []

limit = min(limit, MAX_LIMIT)

return (
Milestone.objects.filter(
repository__in=root.repositories.all(),
Expand All @@ -95,12 +111,8 @@ def recent_milestones(self, root: Project, limit: int = 5) -> list[MilestoneNode
"repository__organization",
"author__owasp_profile",
)
.prefetch_related(
"labels",
)
.prefetch_related("labels")
.order_by("-created_at")[:limit]
if (limit := min(limit, MAX_LIMIT)) > 0
else []
)

@strawberry_django.field
Expand Down
16 changes: 11 additions & 5 deletions backend/apps/owasp/api/internal/queries/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,17 @@ def recent_projects(self, limit: int = 8) -> list[ProjectNode]:
list[ProjectNode]: A list of recent active projects.

"""
return (
Project.objects.filter(is_active=True).order_by("-created_at")[:limit]
if (limit := min(limit, MAX_RECENT_PROJECTS_LIMIT)) > 0
else []
)
try:
limit = int(limit)
except (TypeError, ValueError):
return []

if limit <= 0:
return []

limit = min(limit, MAX_RECENT_PROJECTS_LIMIT)

return Project.objects.filter(is_active=True).order_by("-created_at")[:limit]

@strawberry_django.field
def search_projects(self, query: str) -> list[ProjectNode]:
Expand Down