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

Reduce amount of rules in routes json file #394

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

veitbjarsch
Copy link
Contributor

Changes

Cloudflare has a limit of 100 includes/exclude rules. In many applications this amount is reached quite fast.
This PR add the functionality to compare include and exclude rules and reduce the amount of rules wherever possible.
Therefore it:

  • adds a wildcard if a folder only belogs to include or exclude rules
  • skips all subfolders where a wildcard is already present (leave them untouched)

Testing

Tested in out own project using cloudflare as well wrote a unit test here.

Docs

Copy link

changeset-bot bot commented Sep 16, 2024

🦋 Changeset detected

Latest commit: 0bdc386

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

This PR includes changesets to release 10 packages
Name Type
@astrojs/cloudflare Minor
@test/astro-cloudflare-astro-dev-platform Patch
@test/astro-cloudflare-astro-env Patch
@test/astro-cloudflare-compile-image-service Patch
@test/astro-cloudflare-external-image-service Patch
@test/astro-cloudflare-wasm Patch
@test/astro-cloudflare-no-output Patch
@test/astro-cloudflare-routes-json Patch
@test/astro-cloudflare-with-solid-js Patch
@test/astro-cloudflare-wrangler-preview-platform Patch

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

@alexanderniebuhr
Copy link
Member

@veitbjarsch Thank you for this contribution, I'll check it later to see if it works with all requirements outlined in this issue #374

@alexanderniebuhr
Copy link
Member

adds a wildcard if a folder only belogs to include or exclude rules

I have to check this internally, but I think we can't tell this upfront, either in all cases or in specific cases.

skips all subfolders where a wildcard is already present (leave them untouched)

That's a good addition, we need to see how it handles the routes if you have all static in one folder and then one dynamic route in a nested subfolder. I'll take a look at your testcase.

@veitbjarsch
Copy link
Contributor Author

@alexanderniebuhr Thanks for your fast response.

skips all subfolders where a wildcard is already present (leave them untouched)

That's a good addition, we need to see how it handles the routes if you have all static in one folder and then one dynamic route in a nested subfolder. I'll take a look at your testcase.

The code compares both includes and excludes in 2 ways. This means if the same folder (partial path) is present in both PathTrie objects, it will leave them untouched. Only if a folder is not present in the other PathTrie object we can savely assume that all children belongs to the current PathTrie. Only in this case we add the wildcard flag for this folder.

This way we can reduce the amount of rules in our project by more than 50% automatically, without the need to create and handle the routes.jsnon manually.

@alexanderniebuhr
Copy link
Member

Sounds good, I did a quick test and it seems to be working with all the cases. I'll give it a proper review later :)

@veitbjarsch
Copy link
Contributor Author

Thanks

@alexanderniebuhr
Copy link
Member

@veitbjarsch can you add an changeset with pnpm exec changeset

@veitbjarsch
Copy link
Contributor Author

@alexanderniebuhr added the changeset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants