parse-server
parse-server copied to clipboard
perf: Initialize authentication adapters only once at server start
Pull Request
- Report security issues confidentially.
- Any contribution is under this license.
- Link this pull request to an issue.
Issue
Currently, AuthAdapters can be constructed each time a auth call is called. This means validateOptions is called too much.
Closes: #8463
Approach
Loads adapters on server init
Tasks
- [x] Add tests
I will reformat the title to use the proper commit message syntax.
Thanks for opening this pull request!
Codecov Report
Attention: Patch coverage is 74.07407% with 7 lines in your changes are missing coverage. Please review.
Project coverage is 94.40%. Comparing base (
b07ec15) to head (e8806a3). Report is 3 commits behind head on alpha.
:exclamation: Current head e8806a3 differs from pull request most recent head a02a0ff. Consider uploading reports for the commit a02a0ff to get more accurate results
| Files | Patch % | Lines |
|---|---|---|
| src/Adapters/Auth/AuthAdapter.js | 0.00% | 5 Missing :warning: |
| src/Adapters/Auth/index.js | 89.47% | 2 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## alpha #8464 +/- ##
==========================================
+ Coverage 94.15% 94.40% +0.24%
==========================================
Files 186 184 -2
Lines 14688 14625 -63
==========================================
- Hits 13829 13806 -23
+ Misses 859 819 -40
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
If this a performance improvement or just an code style refactor without significant implications?
It should be a minor performance increase, but mostly intended as a functionality change as at the moment errors in auth config are only called once the auth is used.
Most of the old auth adapters are js objects so reconstruction probably has minimal impact. As we move towards making them AuthAdapter classes, preventing reconstruction might be preferable
Okay; then let's use perf commit type.
Cache is required here otherwise each adapter is constructed each time an auth method is called. An auth adapter should be constructed once and then used across the rest of the server instance
It seems that the tests are passing; is this ready for merge?