Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ workflows:
branches:
only:
- develop
- pm-2539

# Production builds are exectuted only on tagged commits to the
# master branch.
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/trivy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Trivy Scanner

permissions:
contents: read
security-events: write
on:
push:
branches:
- main
- dev
pull_request:
jobs:
trivy-scan:
name: Use Trivy
runs-on: ubuntu-24.04

Choose a reason for hiding this comment

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

[⚠️ maintainability]
Consider using a stable version of the runner, such as ubuntu-latest, instead of ubuntu-24.04 to ensure compatibility and support. The specific version ubuntu-24.04 may not be available or supported in the future.

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run Trivy scanner in repo mode
uses: aquasecurity/trivy-action@0.33.1
with:
scan-type: "fs"
ignore-unfixed: true
format: "sarif"
output: "trivy-results.sarif"
severity: "CRITICAL,HIGH,UNKNOWN"

Choose a reason for hiding this comment

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

[❗❗ correctness]
The severity level UNKNOWN is not a standard Trivy severity level. Consider removing it to avoid potential issues with the scan results.

scanners: vuln,secret,misconfig,license
github-pat: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: "trivy-results.sarif"
17 changes: 17 additions & 0 deletions prisma/migrations/20251023103423_performance_indices/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- CreateIndex
CREATE INDEX "Group_status_organizationId_idx" ON "Group"("status", "organizationId");

Choose a reason for hiding this comment

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

[⚠️ performance]
Consider evaluating the selectivity of the status and organizationId columns. If either column has low cardinality, the index might not significantly improve query performance.


-- CreateIndex
CREATE INDEX "Group_domain_idx" ON "Group"("domain");

Choose a reason for hiding this comment

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

[⚠️ performance]
Ensure that the domain column has a high cardinality. Indexing columns with low cardinality may not provide significant performance benefits.


-- CreateIndex
CREATE INDEX "Group_ssoId_idx" ON "Group"("ssoId");

Choose a reason for hiding this comment

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

[⚠️ performance]
Verify that the ssoId column is frequently used in query filters or joins. Indexing columns that are rarely used in queries may not be beneficial.


-- CreateIndex
CREATE INDEX "Group_privateGroup_status_idx" ON "Group"("privateGroup", "status");

Choose a reason for hiding this comment

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

[⚠️ performance]
Check the cardinality of the privateGroup and status columns. Indexing columns with low cardinality might not yield substantial performance improvements.


-- CreateIndex
CREATE INDEX "GroupMember_memberId_membershipType_idx" ON "GroupMember"("memberId", "membershipType");

Choose a reason for hiding this comment

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

[⚠️ performance]
Ensure that the memberId and membershipType columns are frequently queried together. If not, consider separate indexes or reevaluating the need for this composite index.


-- CreateIndex
CREATE INDEX "User_universalUID_idx" ON "User"("universalUID");

Choose a reason for hiding this comment

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

[⚠️ performance]
Verify that the universalUID column is used in query filters or joins. Indexing columns that are not frequently queried may not be necessary.

9 changes: 8 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ model Group {
@@index([name]) // Index for filtering by name
@@index([status]) // Index for filtering by status
@@index([oldId]) // Index for filtering by oldId
@@index([status, organizationId])

Choose a reason for hiding this comment

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

[⚠️ performance]
Consider the potential impact on query performance when adding multiple indexes. While adding indexes can improve read performance, it can also slow down write operations and increase storage requirements. Ensure that these indexes are necessary for your application's query patterns.

@@index([domain])
@@index([ssoId])
@@index([privateGroup, status])
}

model GroupMembership {
Expand All @@ -63,7 +67,8 @@ model GroupMembership {
@@unique([groupId, memberId])
@@index([groupId]) // Index for joining with group table
@@index([memberId]) // Index for filtering by memberId
@@map("GroupMember")
@@index([memberId, membershipType])

Choose a reason for hiding this comment

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

[⚠️ performance]
Ensure that the new index on [memberId, membershipType] aligns with your query patterns. Adding composite indexes can be beneficial, but they should be justified by actual query needs to avoid unnecessary overhead.

@@map("GroupMember")
}

// This user table is only used in this group challenge
Expand All @@ -74,4 +79,6 @@ model User {
createdBy String
updatedAt DateTime @updatedAt
updatedBy String?

@@index([universalUID])

Choose a reason for hiding this comment

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

[⚠️ performance]
Adding an index on universalUID is generally beneficial for lookups, but ensure that this field is queried frequently enough to justify the index. Consider the trade-offs in write performance and storage.

}
5 changes: 5 additions & 0 deletions src/shared/modules/global/prisma.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export class PrismaService

constructor(private readonly prismaErrorService?: PrismaErrorService) {
super({
transactionOptions: {
timeout: process.env.GROUPS_SERVICE_PRISMA_TIMEOUT

Choose a reason for hiding this comment

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

[⚠️ correctness]
Consider validating the environment variable process.env.GROUPS_SERVICE_PRISMA_TIMEOUT to ensure it is a valid number before parsing. This will prevent potential runtime errors if the environment variable is set to a non-numeric value.

? parseInt(process.env.GROUPS_SERVICE_PRISMA_TIMEOUT, 10)
: 10000,
},
log: [
{ level: 'query', emit: 'event' },
{ level: 'info', emit: 'event' },
Expand Down