diff options
| author | syuilo <4439005+syuilo@users.noreply.github.com> | 2024-10-13 20:22:16 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-13 20:22:16 +0900 |
| commit | ff47fef5725ba31efc7016534c2d9db8b0ad242a (patch) | |
| tree | 8cb84a5c3fcccaf6f67d7384a86412e0368d9d99 /packages/backend/src/core/FederatedInstanceService.ts | |
| parent | feat: ユーザーの名前に禁止ワードを設定できるように (#14... (diff) | |
| download | sharkey-ff47fef5725ba31efc7016534c2d9db8b0ad242a.tar.gz sharkey-ff47fef5725ba31efc7016534c2d9db8b0ad242a.tar.bz2 sharkey-ff47fef5725ba31efc7016534c2d9db8b0ad242a.zip | |
feat: リモートサーバーのサーバー情報を収集しないオプション (#14634)
* wip
* wip
* Update FetchInstanceMetadataService.ts
* Update FetchInstanceMetadataService.ts
* Update types.ts
Diffstat (limited to 'packages/backend/src/core/FederatedInstanceService.ts')
| -rw-r--r-- | packages/backend/src/core/FederatedInstanceService.ts | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/packages/backend/src/core/FederatedInstanceService.ts b/packages/backend/src/core/FederatedInstanceService.ts index 7aeeb78178..73bbf03b26 100644 --- a/packages/backend/src/core/FederatedInstanceService.ts +++ b/packages/backend/src/core/FederatedInstanceService.ts @@ -47,7 +47,7 @@ export class FederatedInstanceService implements OnApplicationShutdown { } @bindThis - public async fetch(host: string): Promise<MiInstance> { + public async fetchOrRegister(host: string): Promise<MiInstance> { host = this.utilityService.toPuny(host); const cached = await this.federatedInstanceCache.get(host); @@ -71,6 +71,24 @@ export class FederatedInstanceService implements OnApplicationShutdown { } @bindThis + public async fetch(host: string): Promise<MiInstance | null> { + host = this.utilityService.toPuny(host); + + const cached = await this.federatedInstanceCache.get(host); + if (cached !== undefined) return cached; + + const index = await this.instancesRepository.findOneBy({ host }); + + if (index == null) { + this.federatedInstanceCache.set(host, null); + return null; + } else { + this.federatedInstanceCache.set(host, index); + return index; + } + } + + @bindThis public async update(id: MiInstance['id'], data: Partial<MiInstance>): Promise<void> { const result = await this.instancesRepository.createQueryBuilder().update() .set(data) |