parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

perf: Initialize authentication adapters only once at server start

Open dblythy opened this issue 2 years ago • 8 comments
trafficstars

Pull Request

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

dblythy avatar Mar 07 '23 06:03 dblythy

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.

codecov[bot] avatar Mar 07 '23 07:03 codecov[bot]

If this a performance improvement or just an code style refactor without significant implications?

mtrezza avatar Mar 07 '23 16:03 mtrezza

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

dblythy avatar Mar 07 '23 19:03 dblythy

Okay; then let's use perf commit type.

mtrezza avatar Mar 07 '23 21:03 mtrezza

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

dblythy avatar May 16 '23 07:05 dblythy

It seems that the tests are passing; is this ready for merge?

mtrezza avatar Jun 09 '23 12:06 mtrezza