Closed criyle closed 2 months ago
LGTM, but you may need edit @hydrooj/migrate too, then you can direct await in
result = await h(password, this._salt, this);
.See https://github.com/hydro-dev/Hydro/blob/master/packages/migrate/index.ts#L62 .
I don't want to break the existing plugin system by this change since there might be other implementation of customized plugin which defines their own hash functions or there might be someone who forget to upgrade migrate
plugins with hydrooj
. At the same time, I believe this implementation just extend the current functionality to support async hash functions without a breaking change.
I found that await a value which is not a promise always returns itself, so changed to result = await h(password, this._salt, this);
anyway.
The
pbkdf2
function is a CPU consuming operation (~50ms on m1) so usingsync
version blocks the Nodejs event loop for a while during request. Changing it into async version allows it to be calculated in worker thread without blocking. Stress test shows ~75% latency reduction.before:
after: