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 the impact on every request #22

Merged
merged 3 commits into from May 8, 2019
Merged

Conversation

rik
Copy link
Contributor

@rik rik commented May 7, 2019

  • Use a set for faster membership test
  • Generate the header once at boot time
  • Disable the middleware if no header need to be added

fixes #21

@rik
Copy link
Contributor Author

rik commented May 7, 2019

Surprisingly, I didn't need to use signals for the tests. I'm not really sure why.

rik and others added 3 commits May 8, 2019 11:32
- Use a set for faster membership test
- Generate the header once at boot time
- Disable the middleware if no header need to be added

fixes adamchainz#21
@adamchainz adamchainz merged commit cbb35db into adamchainz:master May 8, 2019
@adamchainz
Copy link
Owner

The signal wasn't needed since the test client is instantiated per-test in the pytest client fixture.

I added a test for this that failed: test_setting_changing

It's best not to disable the middleware since users might want to change feature-policy in their tests, or (hopefully not) at run-time. I refactored to use Django's cached_property rather than custom logic, and clear that with a signal receiver when the setting changes.

Thanks for your contributions that I've released in version 2.2.0!

@rik rik deleted the speed-ups branch January 24, 2024 00:36
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.

Ideas to reduce the CPU impact of this middleware
2 participants