-
Notifications
You must be signed in to change notification settings - Fork 29
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
Feature: add cache checking middleware and APISchema #151 #159
Feature: add cache checking middleware and APISchema #151 #159
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov ReportPatch coverage:
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## develop #159 +/- ##
===========================================
+ Coverage 92.97% 93.02% +0.05%
===========================================
Files 289 291 +2
Lines 4398 4444 +46
Branches 582 597 +15
===========================================
+ Hits 4089 4134 +45
Misses 200 200
- Partials 109 110 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
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.
Beside all comment suggestions, other is LGTM.
cacheTableName: 'test_cache', | ||
sql: 'SELECT * FROM test_table', | ||
refreshTime: { every: '5m' }, | ||
refreshExpression: { expression: '*/5,*,*,*,*', every: '5m' }, |
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.
Suggest changing the value */5,*,*,*,*
of "expression", because other members or new members often trace the test cases to understand the user case, when using non-relative values, it will make them confused, for example, the "expression" often use be a column value or the result from call SQL function.
Like the #151, description, the MAX(created_at)
is used to get the created_at
max value from the query result to check refreshes or not.
If not sure how to give the value in the test case, suggest figuring out the user scenario of #150 by discussion.
Otherwise, when writing test cases, we often use sinon
to stub the value for the unnecessary part to make other members know what part is that we would like to focus on the test or use fake.js
to fake the value.
packages/build/test/schema-parser/middleware/checkCache.spec.ts
Outdated
Show resolved
Hide resolved
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.
There is a suggestion that seems you miss to fix, otherwise other fixed parts still have some minor suggestions, please check it :D
} | ||
if (!isUsedCache && caches) { | ||
throw new ConfigurationError( | ||
`Can not configurate the cache setting in Schema ${schemas.urlPath}, {% cache %} tag not been used in SQL file.` |
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.
-
Misspelling for
configurate
, please update the word. -
After discussion although the
${schemas.urlPath}
may be long and make the message not easy to read, we still keep it until the cases happened ( If happened, change tosourceName
). -
Otherwise, suggest adding the "..." in the
${schemas.sourceName}
to highlight it, btw let us make the Schema to lowercase for consistency
// throw if cache not used in .sql file | ||
if (isUsedCache && !caches) { | ||
throw new ConfigurationError( | ||
`{% cache %} tag was used in SQL file, but the cache configurations was not found in Schema ${schemas.urlPath}.` |
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.
For the ${schemas.urlPath}
, it's the same suggestion to add a double quote on it, btw let us make the Schema to lowercase for consistency
const { refreshTime, refreshExpression } = cache; | ||
if (refreshTime && refreshExpression) { | ||
throw new ConfigurationError( | ||
`The cache ${cache.cacheTableName} of Schema ${schemas.urlPath} is invalid: Can not configure refreshTime and refreshExpression at the same time, please pick one` |
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.
The error message is so long, suggest making it lighter,
e.g: Can not set "refreshTime" and "refreshExpression" at the same time in cache ${cache.cacheTableName} of schema ${schemas.urlPath}
.
// check "every" of "refreshTime" is valid | ||
let every = refreshTime?.['every']; | ||
if (every) { | ||
const { isValid, error } = this.checkRefreshInterval(every); | ||
if (!isValid) { | ||
throw new ConfigurationError( | ||
`The "every" of "refreshTime" in cache ${cache.cacheTableName} of schema ${schemas.urlPath} is invalid: ${error}` | ||
); | ||
} | ||
} | ||
// check "every" of "refreshExpression" is valid | ||
every = refreshExpression?.['every']; | ||
if (every) { | ||
const { isValid, error } = this.checkRefreshInterval(every); | ||
if (!isValid) { | ||
throw new ConfigurationError( | ||
`The "every" of "refreshExpression" in cache ${cache.cacheTableName} of schema ${schemas.urlPath} is invalid: ${error}` | ||
); | ||
} | ||
} |
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.
-
This code is similar, could we refactor it by extracting it to a private method?
-
The error message is better now ~ minor suggestion like above, add a double quote on
${schemas.urlPath}
,
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.
Hi @onlyjackfrost have you missed the suggestion ?
Close this PR due to Github does not detect the latest commit. |
Description
This pull request adds a new middleware to validate cache configurations defined in the .yaml file.
Validation logic:
Issue ticket number
issue #151
Additional Context