implement followingCountDelta and followersCountDelta in updateUserQueue
This commit is contained in:
parent
c2aa46618d
commit
1d44a27505
2 changed files with 11 additions and 8 deletions
|
|
@ -29,6 +29,8 @@ export type UpdateInstanceJob = {
|
|||
export type UpdateUserJob = {
|
||||
updatedAt?: Date,
|
||||
notesCountDelta?: number,
|
||||
followingCountDelta?: number,
|
||||
followersCountDelta?: number,
|
||||
};
|
||||
|
||||
export type UpdateNoteJob = {
|
||||
|
|
@ -97,10 +99,14 @@ export class CollapsedQueueService implements OnApplicationShutdown {
|
|||
(oldJob, newJob) => ({
|
||||
updatedAt: maxDate(oldJob.updatedAt, newJob.updatedAt),
|
||||
notesCountDelta: (oldJob.notesCountDelta ?? 0) + (newJob.notesCountDelta ?? 0),
|
||||
followingCountDelta: (oldJob.followingCountDelta ?? 0) + (newJob.followingCountDelta ?? 0),
|
||||
followersCountDelta: (oldJob.followersCountDelta ?? 0) + (newJob.followersCountDelta ?? 0),
|
||||
}),
|
||||
(id, job) => this.usersRepository.update({ id }, {
|
||||
updatedAt: job.updatedAt,
|
||||
notesCount: job.notesCountDelta ? () => `"notesCount" + ${job.notesCountDelta}` : undefined,
|
||||
followingCount: job.followingCountDelta ? () => `"followingCount" + ${job.followingCountDelta}` : undefined,
|
||||
followersCount: job.followersCountDelta ? () => `"followersCount" + ${job.followersCountDelta}` : undefined,
|
||||
}),
|
||||
{
|
||||
onError: this.onQueueError,
|
||||
|
|
@ -170,6 +176,7 @@ export class CollapsedQueueService implements OnApplicationShutdown {
|
|||
|
||||
async onApplicationShutdown() {
|
||||
// TODO note/user delete events
|
||||
// TODO remove updated events
|
||||
this.internalEventService.off('localUserUpdated', this.onUserUpdated);
|
||||
this.internalEventService.off('remoteUserUpdated', this.onUserUpdated);
|
||||
|
||||
|
|
|
|||
|
|
@ -288,10 +288,8 @@ export class UserFollowingService implements OnModuleInit {
|
|||
// Neither followee nor follower has moved.
|
||||
if (!followeeUser.movedToUri && !followerUser.movedToUri) {
|
||||
//#region Increment counts
|
||||
await Promise.all([
|
||||
this.usersRepository.increment({ id: follower.id }, 'followingCount', 1),
|
||||
this.usersRepository.increment({ id: followee.id }, 'followersCount', 1),
|
||||
]);
|
||||
this.collapsedQueueService.updateUserQueue.enqueue(follower.id, { followingCountDelta: 1 });
|
||||
this.collapsedQueueService.updateUserQueue.enqueue(followee.id, { followersCountDelta: 1 });
|
||||
//#endregion
|
||||
|
||||
//#region Update instance stats
|
||||
|
|
@ -400,10 +398,8 @@ export class UserFollowingService implements OnModuleInit {
|
|||
// Neither followee nor follower has moved.
|
||||
if (!follower.movedToUri && !followee.movedToUri) {
|
||||
//#region Decrement following / followers counts
|
||||
await Promise.all([
|
||||
this.usersRepository.decrement({ id: follower.id }, 'followingCount', 1),
|
||||
this.usersRepository.decrement({ id: followee.id }, 'followersCount', 1),
|
||||
]);
|
||||
this.collapsedQueueService.updateUserQueue.enqueue(follower.id, { followingCountDelta: -1 });
|
||||
this.collapsedQueueService.updateUserQueue.enqueue(followee.id, { followersCountDelta: -1 });
|
||||
//#endregion
|
||||
|
||||
//#region Update instance stats
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue