* wrap follow/unfollow and block/unblock as job queue * create import job to follow in each iteration * make relationship jobs concurrent * replace to job queue if called repeatedly * use addBulk to import * omit stream when importing * fix job caller * use ThinUser instead of User to reduce redis memory consumption * createImportFollowingToDbJobの呼び出し方を変える, 型補強 * Force ThinUser * オブジェクト操作のみのメソッド名はgenerate...Data * Force ThinUser in generateRelationshipJobData * silent bulk unfollow at admin api endpoint --------- Co-authored-by: tamaina <tamaina@hotmail.co.jp>
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
import type { FollowingsRepository, UsersRepository } from '@/models/index.js';
|
|
import { DI } from '@/di-symbols.js';
|
|
import { QueueService } from '@/core/QueueService.js';
|
|
|
|
export const meta = {
|
|
tags: ['admin'],
|
|
|
|
requireCredential: true,
|
|
requireModerator: true,
|
|
} as const;
|
|
|
|
export const paramDef = {
|
|
type: 'object',
|
|
properties: {
|
|
host: { type: 'string' },
|
|
},
|
|
required: ['host'],
|
|
} as const;
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
@Injectable()
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
constructor(
|
|
@Inject(DI.usersRepository)
|
|
private usersRepository: UsersRepository,
|
|
|
|
@Inject(DI.notesRepository)
|
|
private followingsRepository: FollowingsRepository,
|
|
|
|
private queueService: QueueService,
|
|
) {
|
|
super(meta, paramDef, async (ps, me) => {
|
|
const followings = await this.followingsRepository.findBy({
|
|
followerHost: ps.host,
|
|
});
|
|
|
|
const pairs = await Promise.all(followings.map(f => Promise.all([
|
|
this.usersRepository.findOneByOrFail({ id: f.followerId }),
|
|
this.usersRepository.findOneByOrFail({ id: f.followeeId }),
|
|
])));
|
|
|
|
this.queueService.createUnfollowJob(pairs.map(p => ({ to: p[0], from: p[1], silent: true })));
|
|
});
|
|
}
|
|
}
|