diff options
| author | syuilo <4439005+syuilo@users.noreply.github.com> | 2025-11-26 20:40:20 +0900 |
|---|---|---|
| committer | syuilo <4439005+syuilo@users.noreply.github.com> | 2025-11-26 20:40:20 +0900 |
| commit | 1590a73d3d38a24fc9d05862dd9e1103041d943e (patch) | |
| tree | d6b1229b6abf79f8253d9feb4f50665af6efb092 /packages/backend/src | |
| parent | fix(deps): update dependency glob to v11.1.0 [security] [ci skip] (#16861) (diff) | |
| download | misskey-1590a73d3d38a24fc9d05862dd9e1103041d943e.tar.gz misskey-1590a73d3d38a24fc9d05862dd9e1103041d943e.tar.bz2 misskey-1590a73d3d38a24fc9d05862dd9e1103041d943e.zip | |
perf(backend): 必要になるまでnsfwjsを読み込まないように
Diffstat (limited to 'packages/backend/src')
| -rw-r--r-- | packages/backend/src/core/AiService.ts | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/packages/backend/src/core/AiService.ts b/packages/backend/src/core/AiService.ts index 23ab8082ed..7a005400bb 100644 --- a/packages/backend/src/core/AiService.ts +++ b/packages/backend/src/core/AiService.ts @@ -7,11 +7,11 @@ import * as fs from 'node:fs'; import { fileURLToPath } from 'node:url'; import { dirname } from 'node:path'; import { Injectable } from '@nestjs/common'; -import * as nsfw from 'nsfwjs'; import si from 'systeminformation'; import { Mutex } from 'async-mutex'; import fetch from 'node-fetch'; import { bindThis } from '@/decorators.js'; +import type { NSFWJS, PredictionType } from 'nsfwjs'; const _filename = fileURLToPath(import.meta.url); const _dirname = dirname(_filename); @@ -21,7 +21,7 @@ let isSupportedCpu: undefined | boolean = undefined; @Injectable() export class AiService { - private model: nsfw.NSFWJS; + private model: NSFWJS; private modelLoadMutex: Mutex = new Mutex(); constructor( @@ -29,7 +29,7 @@ export class AiService { } @bindThis - public async detectSensitive(source: string | Buffer): Promise<nsfw.PredictionType[] | null> { + public async detectSensitive(source: string | Buffer): Promise<PredictionType[] | null> { try { if (isSupportedCpu === undefined) { isSupportedCpu = await this.computeIsSupportedCpu(); @@ -44,6 +44,7 @@ export class AiService { tf.env().global.fetch = fetch; if (this.model == null) { + const nsfw = await import('nsfwjs'); await this.modelLoadMutex.runExclusive(async () => { if (this.model == null) { this.model = await nsfw.load(`file://${_dirname}/../../nsfw-model/`, { size: 299 }); |