mirror of
https://github.com/immich-app/immich.git
synced 2026-09-30 13:23:21 +08:00
perf: faster server cold start (#31630)
low hanging fruits for the speedup of immich startup 1. don't wait 1s if we actually got the lock 2. move full import from the top of the file to be imported lazily in the branch
This commit is contained in:
+8
-3
@@ -4,7 +4,6 @@ import { ChildProcess, fork } from 'node:child_process';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { Worker } from 'node:worker_threads';
|
||||
import { PostgresError } from 'postgres';
|
||||
import { ImmichAdminModule } from 'src/app.module.js';
|
||||
import { DatabaseLock, ExitCode, ImmichWorker, LogLevel, SystemMetadataKey } from 'src/enum.js';
|
||||
import { ConfigRepository } from 'src/repositories/config.repository.js';
|
||||
import { SystemMetadataRepository } from 'src/repositories/system-metadata.repository.js';
|
||||
@@ -84,7 +83,9 @@ class Workers {
|
||||
return isLocked;
|
||||
});
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
if (!isLocked) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
}
|
||||
}
|
||||
|
||||
await kysely.destroy();
|
||||
@@ -161,7 +162,7 @@ class Workers {
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
async function main() {
|
||||
const immichApp = process.argv[2];
|
||||
if (immichApp) {
|
||||
process.argv.splice(2, 1);
|
||||
@@ -171,6 +172,10 @@ function main() {
|
||||
process.title = 'immich_admin_cli';
|
||||
process.env.IMMICH_LOG_LEVEL = LogLevel.Warn;
|
||||
|
||||
// imported lazily, so that the supervisor process does not build the whole application
|
||||
// graph on every start.
|
||||
const { ImmichAdminModule } = await import('./app.module.js');
|
||||
|
||||
return CommandFactory.run(ImmichAdminModule);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user