Skip to content
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

fix(cache): imporove cache performance and resolve cache mistake #344

Merged
merged 1 commit into from
Mar 9, 2023
Merged

fix(cache): imporove cache performance and resolve cache mistake #344

merged 1 commit into from
Mar 9, 2023

Conversation

lishaobos
Copy link
Collaborator

@lishaobos lishaobos commented Mar 9, 2023

Resolve

  1. when code does not need auto inject api and relevant cache should be removed.
  2. imporove cache performance and resolve mistake cause by race condition.

@@ -206,11 +208,11 @@ ${dts}`.trim()}\n`

const res = await unimport.injectImports(s, id)

await updateCacheImports(id, res.imports)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

is point one!

await unimport.modifyDynamicImports(async (imports) => {
const cacheData = await getCacheData(cachePath)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

cache data does not need alwawys read

if (id && importList) {
const filePath = posix.normalize(posix.relative(root, id))
importList = importList.filter(i => (i.name ?? i.as) && i.name !== 'default')
if (importList.length)
cacheData[filePath] = importList
else
delete cacheData[filePath]
await writeFile(cachePath, JSON.stringify(cacheData, null, 2))
writeFileThrottled(cachePath, JSON.stringify(cacheData, null, 2))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

write file need add throttle

@antfu antfu merged commit c5a5fcc into unplugin:main Mar 9, 2023
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.

None yet

2 participants