Skip to content

Conversation

@jmgasper
Copy link
Contributor

@jmgasper jmgasper commented Nov 3, 2025

No description provided.

cb."challengeId" AS challenge_id,
MAX(cb."billingAccountId") FILTER (WHERE cb."billingAccountId" IS NOT NULL) AS billing_account_id
FROM challenges."ChallengeBilling" cb
WHERE cb."billingAccountId" = '80000062'
Copy link

Choose a reason for hiding this comment

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

[⚠️ maintainability]
The hardcoded billing account ID '80000062' in the WHERE clause could be extracted as a parameter to improve maintainability and flexibility of the query. This would allow for easier changes in the future if the billing account ID needs to be updated or if the query needs to be reused with different IDs.

FROM challenges."Challenge" c
JOIN bill b
ON b.challenge_id = c.id
WHERE c."createdAt" >= now() - interval '4 months'
Copy link

Choose a reason for hiding this comment

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

[⚠️ correctness]
The use of now() - interval '4 months' in the WHERE clause could lead to inconsistent results if the query is run multiple times within a short period. Consider using a fixed date or a parameter to ensure consistent results across executions.

bc."registrationStartDate" AS registration_start_date,
CASE
WHEN bc.status = 'COMPLETED'
AND bc."createdAt" > '2025-01-01T00:00:00Z'
Copy link

Choose a reason for hiding this comment

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

[⚠️ maintainability]
The condition bc."createdAt" > '2025-01-01T00:00:00Z' is hardcoded and may become obsolete over time. Consider using a parameter or a configuration setting to make this condition more flexible and maintainable.

AND bc.status = 'COMPLETED'
AND bc."createdAt" > '2025-01-01T00:00:00Z'
) cp ON TRUE
WHERE bc.billing_account_id = '80000062'
Copy link

Choose a reason for hiding this comment

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

[⚠️ performance]
The ORDER BY bc."createdAt" DESC clause assumes that createdAt is indexed and will perform well. Ensure that there is an appropriate index on createdAt to avoid potential performance issues with large datasets.

@jmgasper jmgasper merged commit 8ed3873 into master Nov 3, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants