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 tracked queries when deleting stale page-data files #29431

Merged
merged 2 commits into from
Feb 10, 2021

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Feb 10, 2021

Description

Deleting stale page-data files from previous builds doesn't clean up our query tracking state. This can result in following kind of errors at SSG step:

error: ENOENT: no such file or directory, open '/Users/misiek/dev/pgs-gatsby/integration-tests/artifac
  ts/public/page-data/stale-pages/only-in-first/page-data.json'

It can be reproduced by conditionally adding/removing page between builds where we wouldn't clear cache in between runs:

  • page 1: build page X
  • page 2: don't build page X (just not create this page) - here page-data for page X will be deleted, but queries reducer will still keep track of it
  • page 3: build page X again (page-data doesn't exist but we don't recreate page-data because cache thinks it still exists) -> result in error trying to read file that doesn't exist

Note - this is more of a hot fix. Proper fix #28590 and #28760 (as in persisting pages to be able to rely on already existing DELETE_PAGE action handler in queries reducer (which just doesn't happen right now because pages are not persisted)

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Feb 10, 2021
if (!expectedPageDataFiles.has(pageDataFilePath)) {
const stalePageDataContent = await fs.readJson(pageDataFilePath)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this adds fs operation - but just for page-data files that are marked as stale and scheduled for deletion. This is to grab page.path.

Alternatively we could try to derive page.path from location of page-data file, but this is not deterministic due to all the variations of leading and trailing slashes ... and it also would be more convoluted.

Copy link
Contributor

Choose a reason for hiding this comment

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

A nice trick to get this path! 😄

@pieh pieh added topic: stale-artifacts* and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Feb 10, 2021
ghost
ghost previously approved these changes Feb 10, 2021
@pieh
Copy link
Contributor Author

pieh commented Feb 10, 2021

I should add - this might be not needed if instead we would handle #28590 and #28760 (this in fact is sort of a hack, because we don't persist page objects between builds)

@gatsbot
Copy link

gatsbot bot commented Feb 10, 2021

Danger run resulted in 1 fail and 1 markdown; to find out more, see the checks page.

Generated by 🚫 dangerJS

@pieh pieh merged commit 478cf68 into master Feb 10, 2021
@pieh pieh deleted the fix/clear-deleted-page-data-files branch February 10, 2021 17:23
pieh added a commit that referenced this pull request Apr 13, 2021
pieh added a commit that referenced this pull request Apr 13, 2021
pieh added a commit that referenced this pull request Apr 21, 2021
pieh added a commit that referenced this pull request Apr 21, 2021
* add stateful page to artifacts tests

* fix(gatsby): garbage collect stateful pages

* Revert "fix: clear tracked queries when deleting stale page-data files (#29431)" (#30848)

This reverts commit 478cf68.
pieh added a commit that referenced this pull request Apr 22, 2021
* fix(gatsby): add pages to saved redux state

* chore: update test snapshots

* unskip context change scenario for data tracking tests

* mock Date.now so persistance tests don't rely on actual time (needed for updatedAt and snapshot testing)

* refactor persistance tests a bit to allow for creating different pages per test scenario

* shard pages state (on top of existing sharding for nodes)

* drop page count check (there actually might be valid cases for 0 pages)

* only show page context size warning for pages (and not nodes)

* fix lint

* adjust snapshot

* test(artifacts): add case for changing page context

* fix(gatsby): garbage collect stateful pages (#28760)

* add stateful page to artifacts tests

* fix(gatsby): garbage collect stateful pages

* Revert "fix: clear tracked queries when deleting stale page-data files (#29431)" (#30848)

This reverts commit 478cf68.

Co-authored-by: Reda Bacha <mohamedredabacha@hollandandbarrett.com>
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