Skip to content

Commit 7249bee

Browse files
authored
Merge branch 'main' into bugFix/aligned-placement-show-more-btn
2 parents 5a417b4 + d05b469 commit 7249bee

File tree

94 files changed

+2975
-1092
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+2975
-1092
lines changed

.github/workflows/run-ci-cd.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
run_install: false
5959

6060
- name: Set up Node
61-
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e
61+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
6262
with:
6363
node-version: 22
6464
cache: 'pnpm'

.github/workflows/run-code-ql.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141

4242
- name: Set up Node
4343
if: matrix.language == 'javascript-typescript'
44-
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e
44+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
4545
with:
4646
node-version: 22
4747
cache: 'pnpm'

backend/apps/core/utils/index.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def get_params_for_index(index_name):
125125
"idx_location",
126126
"idx_login",
127127
"idx_name",
128+
"idx_public_repositories_count",
128129
"idx_url",
129130
]
130131

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
"""GitHub issue GraphQL node."""
22

3+
import graphene
4+
35
from apps.common.graphql.nodes import BaseNode
46
from apps.github.models.issue import Issue
57

68

79
class IssueNode(BaseNode):
810
"""GitHub issue node."""
911

12+
repository_name = graphene.String()
13+
1014
class Meta:
1115
model = Issue
1216
fields = (
1317
"author",
14-
"comments_count",
1518
"created_at",
1619
"state",
1720
"title",
1821
"url",
1922
)
23+
24+
def resolve_repository_name(self, info):
25+
"""Resolve the repository name."""
26+
return self.repository.name

backend/apps/github/graphql/nodes/pull_request.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
class PullRequestNode(BaseNode):
1010
"""GitHub pull request node."""
1111

12+
repository_name = graphene.String()
1213
url = graphene.String()
1314

1415
class Meta:
@@ -19,6 +20,10 @@ class Meta:
1920
"title",
2021
)
2122

23+
def resolve_repository_name(self, info):
24+
"""Resolve repository name."""
25+
return self.repository.name
26+
2227
def resolve_url(self, info):
2328
"""Resolve URL."""
2429
return self.url

backend/apps/github/graphql/nodes/repository_contributor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ class RepositoryContributorNode(graphene.ObjectType):
1010
contributions_count = graphene.Int()
1111
login = graphene.String()
1212
name = graphene.String()
13+
project_key = graphene.String()
1314
project_name = graphene.String()
14-
project_url = graphene.String()

backend/apps/github/graphql/queries/repository_contributor.py

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
"""OWASP repository contributor GraphQL queries."""
22

33
import graphene
4-
from django.db.models import F, OuterRef, Subquery, Window
4+
from django.db.models import F, Window
55
from django.db.models.functions import Rank
66

77
from apps.common.graphql.queries import BaseQuery
88
from apps.github.graphql.nodes.repository_contributor import RepositoryContributorNode
99
from apps.github.models.repository_contributor import RepositoryContributor
10-
from apps.owasp.models.project import Project
1110

1211

1312
class RepositoryContributorQuery(BaseQuery):
@@ -36,6 +35,14 @@ def resolve_top_contributors(root, info, limit, organization=None):
3635
RepositoryContributor.objects.by_humans()
3736
.to_community_repositories()
3837
.filter(repository__project__isnull=False)
38+
.select_related("repository__project", "user")
39+
.annotate(
40+
rank=Window(
41+
expression=Rank(),
42+
order_by=F("contributions_count").desc(),
43+
partition_by=F("user__login"),
44+
)
45+
)
3946
)
4047

4148
if organization:
@@ -46,34 +53,18 @@ def resolve_top_contributors(root, info, limit, organization=None):
4653
)
4754

4855
top_contributors = (
49-
queryset.annotate(
50-
project_id=Subquery(
51-
Project.repositories.through.objects.filter(
52-
repository=OuterRef("repository_id")
53-
)
54-
.values("project_id")
55-
.order_by("project_id")[:1] # Select the first project ID per repository
56-
),
57-
project_name=Subquery(
58-
Project.objects.filter(id=OuterRef("project_id")).values("name")[:1]
59-
),
60-
project_url=Subquery(
61-
Project.objects.filter(id=OuterRef("project_id")).values("key")[:1]
62-
),
63-
rank=Window(
64-
expression=Rank(),
65-
order_by=F("contributions_count").desc(),
66-
partition_by=F("user__login"),
67-
),
56+
queryset.filter(rank=1)
57+
.annotate(
58+
project_name=F("repository__project__name"),
59+
project_key=F("repository__project__key"),
6860
)
69-
.filter(rank=1) # Keep only the highest contribution per user
7061
.values(
7162
"contributions_count",
7263
"user__avatar_url",
7364
"user__login",
7465
"user__name",
66+
"project_key",
7567
"project_name",
76-
"project_url",
7768
)
7869
.order_by("-contributions_count")[:limit]
7970
)
@@ -84,8 +75,8 @@ def resolve_top_contributors(root, info, limit, organization=None):
8475
contributions_count=trc["contributions_count"],
8576
login=trc["user__login"],
8677
name=trc["user__name"],
78+
project_key=trc["project_key"].replace("www-project-", ""),
8779
project_name=trc["project_name"],
88-
project_url=trc["project_url"],
8980
)
9081
for trc in top_contributors
9182
]

backend/apps/github/index/organization.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class OrganizationIndex(IndexBase):
1919
"idx_location",
2020
"idx_login",
2121
"idx_name",
22+
"idx_public_repositories_count",
2223
"idx_url",
2324
)
2425

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Generated by Django 5.2 on 2025-04-14 07:40
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("github", "0020_repositorycontributor_user_contrib_idx"),
9+
]
10+
11+
operations = [
12+
migrations.AddIndex(
13+
model_name="release",
14+
index=models.Index(fields=["-published_at"], name="release_published_at_desc_idx"),
15+
),
16+
]

backend/apps/github/models/mixins/organization.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ def idx_name(self):
6666
"""Return name for indexing."""
6767
return self.name or ""
6868

69+
@property
70+
def idx_public_repositories_count(self):
71+
"""Return public repositories count for indexing."""
72+
return self.public_repositories_count
73+
6974
@property
7075
def idx_url(self):
7176
"""Return URL for indexing."""

backend/apps/github/models/release.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Meta:
1414
db_table = "github_releases"
1515
indexes = [
1616
models.Index(fields=["-created_at"]),
17+
models.Index(fields=["-published_at"], name="release_published_at_desc_idx"),
1718
]
1819
verbose_name_plural = "Releases"
1920

backend/apps/owasp/graphql/queries/sponsor.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ class SponsorQuery(BaseQuery):
1414

1515
def resolve_sponsors(root, info):
1616
"""Resolve sponsors."""
17-
priority_order = {
18-
Sponsor.SponsorType.DIAMOND: 1,
19-
Sponsor.SponsorType.PLATINUM: 2,
20-
Sponsor.SponsorType.GOLD: 3,
21-
Sponsor.SponsorType.SILVER: 4,
22-
Sponsor.SponsorType.SUPPORTER: 5,
23-
Sponsor.SponsorType.NOT_SPONSOR: 6,
24-
}
25-
return sorted(Sponsor.objects.all(), key=lambda x: priority_order[x.sponsor_type])
17+
return sorted(
18+
Sponsor.objects.all(),
19+
key=lambda x: {
20+
Sponsor.SponsorType.DIAMOND: 1,
21+
Sponsor.SponsorType.PLATINUM: 2,
22+
Sponsor.SponsorType.GOLD: 3,
23+
Sponsor.SponsorType.SILVER: 4,
24+
Sponsor.SponsorType.SUPPORTER: 5,
25+
Sponsor.SponsorType.NOT_SPONSOR: 6,
26+
}[x.sponsor_type],
27+
)

backend/apps/owasp/graphql/queries/stats.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,9 @@ def resolve_stats_overview(self, info, **kwargs):
3636
.count()
3737
)
3838

39-
active_projects_stats = (active_projects_stats // 10) * 10 # nearest 10
40-
active_chapters_stats = (active_chapters_stats // 10) * 10
41-
contributors_stats = (contributors_stats // 100) * 100 # nearest 100
42-
countries_stats = (countries_stats // 10) * 10
43-
4439
return StatsNode(
45-
active_projects_stats,
46-
active_chapters_stats,
47-
contributors_stats,
48-
countries_stats,
40+
(active_projects_stats // 10) * 10, # nearest 10
41+
(active_chapters_stats // 10) * 10, # nearest 10
42+
(contributors_stats // 100) * 100, # nearest 100
43+
(countries_stats // 10) * 10, # nearest 10
4944
)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Generated by Django 5.2 on 2025-04-14 07:27
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("github", "0020_repositorycontributor_user_contrib_idx"),
9+
("owasp", "0030_chapter_is_leaders_policy_compliant_and_more"),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name="chapter",
15+
name="created_at",
16+
field=models.DateTimeField(default=None, verbose_name="Created at"),
17+
),
18+
migrations.AddIndex(
19+
model_name="chapter",
20+
index=models.Index(fields=["-created_at"], name="chapter_created_at_desc_idx"),
21+
),
22+
migrations.AddIndex(
23+
model_name="event",
24+
index=models.Index(fields=["-start_date"], name="event_start_date_desc_idx"),
25+
),
26+
migrations.AddIndex(
27+
model_name="post",
28+
index=models.Index(fields=["-published_at"], name="post_published_at_desc_idx"),
29+
),
30+
migrations.AddIndex(
31+
model_name="project",
32+
index=models.Index(fields=["-created_at"], name="project_created_at_desc_idx"),
33+
),
34+
]

backend/apps/owasp/models/chapter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class Chapter(
2828

2929
class Meta:
3030
db_table = "owasp_chapters"
31+
indexes = [
32+
models.Index(fields=["-created_at"], name="chapter_created_at_desc_idx"),
33+
]
3134
verbose_name_plural = "Chapters"
3235

3336
level = models.CharField(verbose_name="Level", max_length=5, default="", blank=True)

backend/apps/owasp/models/event.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class Event(BulkSaveModel, TimestampedModel):
1717

1818
class Meta:
1919
db_table = "owasp_events"
20+
indexes = [
21+
models.Index(fields=["-start_date"], name="event_start_date_desc_idx"),
22+
]
2023
verbose_name_plural = "Events"
2124

2225
class Category(models.TextChoices):

backend/apps/owasp/models/post.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ class Post(BulkSaveModel, TimestampedModel):
1313

1414
class Meta:
1515
db_table = "owasp_posts"
16+
indexes = [
17+
models.Index(fields=["-published_at"], name="post_published_at_desc_idx"),
18+
]
1619
verbose_name_plural = "Posts"
1720

1821
author_image_url = models.URLField(verbose_name="Author image URL", blank=True, default="")

backend/apps/owasp/models/project.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class Project(
2828

2929
class Meta:
3030
db_table = "owasp_projects"
31+
indexes = [
32+
models.Index(fields=["-created_at"], name="project_created_at_desc_idx"),
33+
]
3134
verbose_name_plural = "Projects"
3235

3336
class ProjectLevel(models.TextChoices):

0 commit comments

Comments
 (0)