-
Notifications
You must be signed in to change notification settings - Fork 83
fix: fixes caching for nested objects and adds tests #3873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: fixes caching for nested objects and adds tests #3873
Conversation
Signed-off-by: Konstantina Blazhukova <konstantina.blajukova@gmail.com>
🎉 Snyk checks have passed. No issues have been found so far.✅ security/snyk check is complete. No issues have been found. (View Details) ✅ license/snyk check is complete. No issues have been found. (View Details) |
…en-added-to-cache-key
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
…en-added-to-cache-key
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can improve the type of generateCacheKey
by using unknown
const generateCacheKey = (methodName: string, args: IArgument[]) => {
const generateCacheKey = (methodName: string, args: unknown[]) => {
Please note that this is not strictly about the issue mentioned in the PR. However, given that in the tests (see below) we type casting to use this function, maybe we can change it here.
Also, we can change the outer loop from
for (const [, value] of Object.entries(args)) {
to
for (const value of args) {
right?
@@ -208,21 +208,21 @@ describe('cache decorator', () => { | |||
|
|||
describe('generateCacheKey', () => { | |||
it('should return only the method name when args are empty', () => { | |||
const args = [] as unknown as IArguments; | |||
const args = [] as unknown as IArguments[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we apply the suggestion left in cache.decorator.ts
comment, we can avoid this casts.
@@ -123,7 +123,9 @@ const generateCacheKey = (methodName: string, args: IArgument[]) => { | |||
if (value?.constructor?.name != 'RequestDetails') { | |||
if (value && typeof value === 'object') { | |||
for (const [key, innerValue] of Object.entries(value)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, now that we are using JSON.stringify
, this loop might not be needed, right?
Description:
Updated the generateCacheKey function to properly serialize nested objects using JSON.stringify()
Related issue(s):
Fixes #3872
Testing