Skip to content

Commit

Permalink
wip: add cache to core
Browse files Browse the repository at this point in the history
  • Loading branch information
bholmesdev committed Mar 9, 2023
1 parent 4bf35ab commit f708b9d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
"react-dom",
"vite"
]
},
"patchedDependencies": {
"astro@2.0.17": "patches/astro@2.0.17.patch"
}
}
}
30 changes: 30 additions & 0 deletions patches/astro@2.0.17.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
diff --git a/dist/content/internal.js b/dist/content/internal.js
index 697a57cdce15610a422f9a42e861f2f4d7d99737..cb9f11759651c0516ee4bbc2334e1c137e5f3bac 100644
--- a/dist/content/internal.js
+++ b/dist/content/internal.js
@@ -28,12 +28,17 @@ function createCollectionToGlobResultMap({
}
return collectionToGlobResultMap;
}
+const cacheByCollection = new Map();
function createGetCollection({
collectionToEntryMap,
collectionToRenderEntryMap
}) {
return async function getCollection(collection, filter) {
const lazyImports = Object.values(collectionToEntryMap[collection] ?? {});
+ // TODO: cache on prod builds only
+ if (cacheByCollection.has(collection)) {
+ return cacheByCollection.get(collection);
+ }
const entries = Promise.all(
lazyImports.map(async (lazyImport) => {
const entry = await lazyImport();
@@ -53,6 +58,7 @@ function createGetCollection({
};
})
);
+ cacheByCollection.set(collection, entries);
if (typeof filter === "function") {
return (await entries).filter(filter);
} else {
16 changes: 11 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f708b9d

Please sign in to comment.