fix: 🐛 trials_used not properly bypassing cache#858
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| .where( | ||
| and( | ||
| or( | ||
| eq(customers.id, fullCus.id ?? ""), |
Contributor
There was a problem hiding this comment.
if fullCus.id is null/undefined (allowed by schema), this becomes eq(customers.id, "") which could match customers with empty string IDs
Suggested change
| eq(customers.id, fullCus.id ?? ""), | |
| fullCus.id ? eq(customers.id, fullCus.id) : undefined, |
Prompt To Fix With AI
This is a comment left during a code review.
Path: server/src/internal/customers/cusUtils/cusResponseUtils/getCusTrialsUsed.ts
Line: 47
Comment:
if `fullCus.id` is null/undefined (allowed by schema), this becomes `eq(customers.id, "")` which could match customers with empty string IDs
```suggestion
fullCus.id ? eq(customers.id, fullCus.id) : undefined,
```
How can I resolve this? If you propose a fix, please make it concise.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by cubic
Fixes trials_used to always read from the database and bypass cached customer data. Also tightens the trial matching to avoid false positives.
Written for commit bba2b03. Summary will update on new commits.
Greptile Summary
This PR successfully addresses the cache bypass issue for
trials_usedby extracting the logic into a separate async function that queries the database directly, rather than relying on potentially stale cached data in thefullCusobject.Key changes:
getCusTrialsUsedinto separate file that performs direct DB query instead of reading from cachedfullCus.trials_usedPromise.allalongside other async expand operations for better performanceThe refactor aligns with the pattern used by other expand functions (
getCusRewards,getCusReferrals) and ensures trials_used data is always fresh from the database.Confidence Score: 3/5
fullCus.idis null. The fix is straightforward but critical for correctness.server/src/internal/customers/cusUtils/cusResponseUtils/getCusTrialsUsed.tsfor the null ID handling bugImportant Files Changed
Last reviewed commit: 0e3e241