diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-05-28 01:31:13 -0400 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-06-04 10:45:05 -0400 |
| commit | 36d712699206f0e197d589a55097b1544db2f62f (patch) | |
| tree | 41589f880dc901d2b3216e8ba55994504e3b3f70 /packages/backend | |
| parent | merge: Rework queries and add indexes to improve timeline performance (!1091) (diff) | |
| download | sharkey-36d712699206f0e197d589a55097b1544db2f62f.tar.gz sharkey-36d712699206f0e197d589a55097b1544db2f62f.tar.bz2 sharkey-36d712699206f0e197d589a55097b1544db2f62f.zip | |
implement InstanceEntityService.fetchInstancesByHost
Diffstat (limited to 'packages/backend')
| -rw-r--r-- | packages/backend/src/core/entities/InstanceEntityService.ts | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/packages/backend/src/core/entities/InstanceEntityService.ts b/packages/backend/src/core/entities/InstanceEntityService.ts index a2ee4b0505..4ca4ff650b 100644 --- a/packages/backend/src/core/entities/InstanceEntityService.ts +++ b/packages/backend/src/core/entities/InstanceEntityService.ts @@ -4,6 +4,7 @@ */ import { Inject, Injectable } from '@nestjs/common'; +import { In } from 'typeorm'; import type { Packed } from '@/misc/json-schema.js'; import type { MiInstance } from '@/models/Instance.js'; import { bindThis } from '@/decorators.js'; @@ -11,7 +12,7 @@ import { UtilityService } from '@/core/UtilityService.js'; import { RoleService } from '@/core/RoleService.js'; import { MiUser } from '@/models/User.js'; import { DI } from '@/di-symbols.js'; -import { MiMeta } from '@/models/_.js'; +import type { InstancesRepository, MiMeta } from '@/models/_.js'; @Injectable() export class InstanceEntityService { @@ -19,6 +20,9 @@ export class InstanceEntityService { @Inject(DI.meta) private meta: MiMeta, + @Inject(DI.instancesRepository) + private readonly instancesRepository: InstancesRepository, + private roleService: RoleService, private utilityService: UtilityService, @@ -73,5 +77,28 @@ export class InstanceEntityService { ) { return Promise.all(instances.map(x => this.pack(x, me))); } + + @bindThis + public async fetchInstancesByHost(instances: (MiInstance | MiInstance['host'])[]): Promise<MiInstance[]> { + const result: MiInstance[] = []; + + const toFetch: string[] = []; + for (const instance of instances) { + if (typeof(instance) === 'string') { + toFetch.push(instance); + } else { + result.push(instance); + } + } + + if (toFetch.length > 0) { + const fetched = await this.instancesRepository.findBy({ + host: In(toFetch), + }); + result.push(...fetched); + } + + return result; + } } |