Skip to content

Commit

Permalink
fix: check if content layer files have changed before writing (#12962)
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic authored Jan 10, 2025
1 parent 1f9571b commit 4b7a2ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-meals-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Skips updating content layer files if content is unchanged
5 changes: 5 additions & 0 deletions packages/astro/src/content/mutable-data-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ export default new Map([\n${lines.join(',\n')}]);

const tempFile = filePath instanceof URL ? new URL(`${filePath.href}.tmp`) : `${filePath}.tmp`;
try {
const oldData = await fs.readFile(filePath, 'utf-8').catch(() => '');
if (oldData === data) {
// If the data hasn't changed, we can skip the write
return;
}
// Write it to a temporary file first and then move it to prevent partial reads.
await fs.writeFile(tempFile, data);
await fs.rename(tempFile, filePath);
Expand Down

0 comments on commit 4b7a2ce

Please sign in to comment.