-
Notifications
You must be signed in to change notification settings - Fork 127
perf: add no cache meta interface #4885
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
Conversation
const meta = state.metaMap[url] | ||
if (meta) { | ||
if (meta && !ignoreCache) { | ||
return new Promise((resolve, reject) => { | ||
resolve(meta) | ||
}) |
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 following is the detailed analysis of the mutations and actions:
-
The difference lies in the
getUrlMeta
mutation. It appears that two instances have been defined, which leads to confusion and potential errors when accessing or using these methods. -
As per current guidelines, it's generally recommended not to use the
Promise.then()
method in Vue.js to return promises directly as it violates a component lifecycle rule.To avoid this violation in production, you could wrap the promise inside another promise object with an
.catch()
to handle possible errors.
- import { AxiosResponse } from 'axios';
...
@@ -30,7 +30,7 @@ export default { | |||
ansible_enabled: true | |||
} | |||
}, | |||
url: `/api/v1/assets/platforms/`, | |||
url: `/api/v1/assets/platforms/?_meta_cache=0`, | |||
disabled: !canEdit, | |||
hasReset: false, | |||
hasDetailInMsg: false, |
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 doesn't seem to be any immediate issue or irregularity with this code snippet based on its current structure and content. However, you could potentially optimize it by checking url
directly if _meta_cache=0
is always expected instead of having separate check for each query. Also, ensure that all other variables used (like ansible_enabled
, disabled
) are defined elsewhere for better maintainability. This might not make much of a difference in terms of performance but improving readability can often lead to clearer comprehension among developers and maintenance process.
Here's an example of how this code could initially look like under these optimizations:
export const platforms = [
// Object definitions...
];
And then define the URLs at the start, so that they don't needlessly depend on additional conditions checked later:
const urlPatterns = {
'/api/v1/assets/platforms/': 'platforms',
}
export default {
...urlPatterns// Use this URL pattern, bypassing the conditional logic when needed
}
export {}
This way, your code would become more self-contained and easy to read while still maintaining flexibility and effectiveness during development cycles.
|
perf: add no cache meta interface