mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 12:36:57 +00:00
implement InstanceEntityService.fetchInstancesByHost
This commit is contained in:
parent
dae544b353
commit
36d7126992
1 changed files with 28 additions and 1 deletions
|
@ -4,6 +4,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
import { In } from 'typeorm';
|
||||||
import type { Packed } from '@/misc/json-schema.js';
|
import type { Packed } from '@/misc/json-schema.js';
|
||||||
import type { MiInstance } from '@/models/Instance.js';
|
import type { MiInstance } from '@/models/Instance.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
|
@ -11,7 +12,7 @@ import { UtilityService } from '@/core/UtilityService.js';
|
||||||
import { RoleService } from '@/core/RoleService.js';
|
import { RoleService } from '@/core/RoleService.js';
|
||||||
import { MiUser } from '@/models/User.js';
|
import { MiUser } from '@/models/User.js';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import { MiMeta } from '@/models/_.js';
|
import type { InstancesRepository, MiMeta } from '@/models/_.js';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class InstanceEntityService {
|
export class InstanceEntityService {
|
||||||
|
@ -19,6 +20,9 @@ export class InstanceEntityService {
|
||||||
@Inject(DI.meta)
|
@Inject(DI.meta)
|
||||||
private meta: MiMeta,
|
private meta: MiMeta,
|
||||||
|
|
||||||
|
@Inject(DI.instancesRepository)
|
||||||
|
private readonly instancesRepository: InstancesRepository,
|
||||||
|
|
||||||
private roleService: RoleService,
|
private roleService: RoleService,
|
||||||
|
|
||||||
private utilityService: UtilityService,
|
private utilityService: UtilityService,
|
||||||
|
@ -73,5 +77,28 @@ export class InstanceEntityService {
|
||||||
) {
|
) {
|
||||||
return Promise.all(instances.map(x => this.pack(x, me)));
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue