Skip to content

Commit

Permalink
Clean up content layer sync in build and sync api
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Dec 4, 2024
1 parent 176fe9f commit 4eb5753
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-teachers-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Cleans up content layer sync during builds and programmatic `sync()` calls
1 change: 1 addition & 0 deletions packages/astro/src/core/dev/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export async function createContainer({
logger,
skip: {
content: true,
cleanup: true,
},
force: inlineConfig?.force,
manifest,
Expand Down
6 changes: 6 additions & 0 deletions packages/astro/src/core/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export type SyncOptions = {
skip?: {
// Must be skipped in dev
content?: boolean;
// Cleanup can be skipped in dev as some state can be reused on updates
cleanup?: boolean;
};
manifest: ManifestData;
};
Expand Down Expand Up @@ -141,6 +143,10 @@ export async function syncInternal({
store,
});
await contentLayer.sync();
if (!skip?.cleanup) {
// Free up memory (usually in builds since we only need to use this once)
contentLayer.dispose();
}
settings.timer.end('Sync content layer');
} else {
const paths = getContentPaths(settings.config, fs);
Expand Down

0 comments on commit 4eb5753

Please sign in to comment.