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

[Content collections] Fast getEntryBySlug() lookup #6916

Merged
merged 22 commits into from May 9, 2023

Conversation

bholmesdev
Copy link
Contributor

@bholmesdev bholmesdev commented Apr 26, 2023

Changes

  • Generate a map from content collection names + entry slugs to the local file path those slugs resolve to. This map is used to resolve imports when using getEntryBySlug().
  • Update getEntryBySlug() to import entries from this lookup map, instead of filtering across the entire collection. This changes O(n) performance to O(1).

Testing

N/A - check that getEntryBySlug() tests still pass

Docs

N/A

@changeset-bot
Copy link

changeset-bot bot commented Apr 26, 2023

🦋 Changeset detected

Latest commit: c05b750

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 Apr 26, 2023
@bholmesdev bholmesdev marked this pull request as ready for review April 26, 2023 19:17
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

Looks great! Got a few nits below. (GitHub pre-comments by initial reviews for some reason)

packages/astro/src/content/runtime.ts Show resolved Hide resolved
packages/astro/src/content/utils.ts Outdated Show resolved Hide resolved
@bholmesdev bholmesdev requested a review from bluwy April 27, 2023 17:21
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for double checking the types.

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 know very little about the logic of the content collections, but I wish the PR description would have better explained the new change.

I left some comments, code-wise.

packages/astro/src/content/utils.ts Outdated Show resolved Hide resolved
packages/astro/src/content/utils.ts Outdated Show resolved Hide resolved
packages/astro/src/content/utils.ts Outdated Show resolved Hide resolved
packages/astro/src/content/utils.ts Show resolved Hide resolved
@bholmesdev bholmesdev force-pushed the feat/fast-entry-by-slug-lookup branch from b6cc10c to e51a349 Compare May 8, 2023 21:00
@bholmesdev bholmesdev merged commit 630f8c8 into main May 9, 2023
14 checks passed
@bholmesdev bholmesdev deleted the feat/fast-entry-by-slug-lookup branch May 9, 2023 16:17
@astrobot-houston astrobot-houston mentioned this pull request May 9, 2023
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.

None yet

3 participants