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: clear the content layer cache when the Astro config changes #12767

Merged
merged 4 commits into from
Dec 18, 2024

Conversation

ascorbic
Copy link
Contributor

Changes

Currently the content layer cache is invalidated if the content config or Astro version changes. However this causes problems if there are changes in the Astro config that also affect the stored data. This can include things like markdown settings, but potentially lots of other things.

The apporach this PR takes is to hash everything except integrations, adapters and vite config. It switches the digest function to use a safe stringify function in case the Astro config includes circular refs.

Closes #12761

Testing

Adds a test case

Docs

Copy link

changeset-bot bot commented Dec 17, 2024

🦋 Changeset detected

Latest commit: 2c1cbc6

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Dec 17, 2024
Copy link

codspeed-hq bot commented Dec 17, 2024

CodSpeed Performance Report

Merging #12767 will not alter performance

Comparing clear-on-config-up (2c1cbc6) with main (8da2318)

Summary

✅ 4 untouched benchmarks

@ascorbic
Copy link
Contributor Author

Huh. They passed locally but now aren't.

@ascorbic ascorbic marked this pull request as draft December 17, 2024 16:31
Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

Tests are failing but looks good to me in principle!

packages/astro/src/content/utils.ts Show resolved Hide resolved
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

I think we should change how we hash the config.

packages/astro/src/content/content-layer.ts Outdated Show resolved Hide resolved
@ascorbic ascorbic marked this pull request as ready for review December 17, 2024 16:55
Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

LGTM!

packages/astro/src/content/content-layer.ts Outdated Show resolved Hide resolved
@delucis
Copy link
Member

delucis commented Dec 17, 2024

Ah, hang on. Seeing “Maximum call stack exceeded” in the object hasher in tests:

error logging reading Maximum call stack exceeded for repeated calls to deterministicString

Node 18 only for some reason, but could still be problematic I guess.

@ascorbic
Copy link
Contributor Author

Oh that isn't good! I'll look into it tomorrow

@ascorbic
Copy link
Contributor Author

I'm going to switch back to the safe stringify approach because it looks like deterministic-object-hash doesn't have any circular dependency handling or any other handling of excessively deep objects. That's fine for simple things like the image transforms, but astro config can be complex.

@ascorbic ascorbic requested a review from delucis December 18, 2024 11:07
@ascorbic ascorbic merged commit 36c1e06 into main Dec 18, 2024
16 checks passed
@ascorbic ascorbic deleted the clear-on-config-up branch December 18, 2024 14:01
@astrobot-houston astrobot-houston mentioned this pull request Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalidate content layer cache when config changes
3 participants