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

feat(content): support useCache option #772

Merged
merged 2 commits into from
Oct 21, 2021

Conversation

kwiatkk1
Copy link
Contributor

@kwiatkk1 kwiatkk1 commented Feb 11, 2021

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

When you have a large number of content files (100+), app startup slows down a lot. It hurts in a development mode (see #694 and #767), but also when you deploy a built app onto a production server.

My proposal is to:

  • during build, if target is server: to serialize content's db into a file
  • during startup, if not in dev mode: do not walk through content's dir and parse found files, but to load content from a file generated during build

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes (if not applicable, please state why)

@atinux atinux requested review from atinux and pi0 February 12, 2021 08:58
@kwiatkk1
Copy link
Contributor Author

It's in a draft, because:

  • it breaks existing tests
  • it hasn't got its own tests

But I hope it shows the general idea. I hope you can look at it and say is it something you want to have in the product?
If so, I'll refine this pull-request.

@pi0
Copy link
Member

pi0 commented Feb 12, 2021

Hi @kwiatkk1 thanks for PR! I think it would be really good idea to use hard-cache to reduce development startup time. I would suggest moving logic load logic into Database.init and use an option to enable hard-cache by constructor or init (maybe cache: true). Also i think we should use generate:done hook since with full-static smart rebuild, we only generate content second time (which needs fresh parsed data)

@kwiatkk1
Copy link
Contributor Author

Hi @pi0, I made some changes:

  • logic hidden behind the useCache flag,
  • tests,
  • sketch of documentation.

This feature doesn't apply to developer mode or the full static generate -- production build only -- I have no idea how to make it work with content reloading :/

@kwiatkk1 kwiatkk1 marked this pull request as ready for review February 12, 2021 21:23
Base automatically changed from dev to main March 2, 2021 11:37
@nozomuikuta nozomuikuta added documentation Improvements or additions to documentation enhancement New feature or request labels Sep 22, 2021
@nozomuikuta nozomuikuta changed the title ssr built app uses serialized content database feat(content): let ssr built app use serialized content database Sep 22, 2021
@pi0 pi0 changed the title feat(content): let ssr built app use serialized content database feat(content): support useCache option Oct 21, 2021
@pi0 pi0 merged commit 9d7f3a0 into nuxt:main Oct 21, 2021
@nozomuikuta
Copy link
Collaborator

@kwiatkk1

Your PR has been merged as Nuxt Content v1.15.0!
Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants