increment/decrement note counts through CollapsedQueueService
This commit is contained in:
parent
28dff9aff9
commit
81fd01d5fa
3 changed files with 10 additions and 27 deletions
|
|
@ -24,7 +24,8 @@ export type UpdateInstanceJob = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UpdateUserJob = {
|
export type UpdateUserJob = {
|
||||||
updatedAt: Date,
|
updatedAt?: Date,
|
||||||
|
additionalNotes?: number,
|
||||||
};
|
};
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|
@ -74,8 +75,12 @@ export class CollapsedQueueService implements OnApplicationShutdown {
|
||||||
fiveMinuteInterval,
|
fiveMinuteInterval,
|
||||||
(oldJob, newJob) => ({
|
(oldJob, newJob) => ({
|
||||||
updatedAt: maxDate(oldJob.updatedAt, newJob.updatedAt),
|
updatedAt: maxDate(oldJob.updatedAt, newJob.updatedAt),
|
||||||
|
additionalNotes: (oldJob.additionalNotes ?? 0) + (newJob.additionalNotes ?? 0),
|
||||||
|
}),
|
||||||
|
(id, job) => this.usersRepository.update({ id }, {
|
||||||
|
updatedAt: job.updatedAt,
|
||||||
|
notesCount: job.additionalNotes ? () => `"notesCount" + ${job.additionalNotes}` : undefined,
|
||||||
}),
|
}),
|
||||||
(id, job) => this.usersRepository.update({ id }, { updatedAt: job.updatedAt }),
|
|
||||||
{
|
{
|
||||||
onError: this.onQueueError,
|
onError: this.onQueueError,
|
||||||
concurrency: 4,
|
concurrency: 4,
|
||||||
|
|
|
||||||
|
|
@ -605,7 +605,7 @@ export class NoteCreateService implements OnApplicationShutdown {
|
||||||
|
|
||||||
if (!this.isRenote(note) || this.isQuote(note)) {
|
if (!this.isRenote(note) || this.isQuote(note)) {
|
||||||
// Increment notes count (user)
|
// Increment notes count (user)
|
||||||
await this.incNotesCountOfUser(user);
|
this.collapsedQueueService.updateUserQueue.enqueue(user.id, { additionalNotes: 1 });
|
||||||
}
|
}
|
||||||
|
|
||||||
this.collapsedQueueService.updateUserQueue.enqueue(user.id, { updatedAt: new Date() });
|
this.collapsedQueueService.updateUserQueue.enqueue(user.id, { updatedAt: new Date() });
|
||||||
|
|
@ -890,17 +890,6 @@ export class NoteCreateService implements OnApplicationShutdown {
|
||||||
await this.searchService.indexNote(note);
|
await this.searchService.indexNote(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
|
||||||
private async incNotesCountOfUser(user: { id: MiUser['id']; }) {
|
|
||||||
await this.usersRepository.createQueryBuilder().update()
|
|
||||||
.set({
|
|
||||||
updatedAt: this.timeService.date,
|
|
||||||
notesCount: () => '"notesCount" + 1',
|
|
||||||
})
|
|
||||||
.where('id = :id', { id: user.id })
|
|
||||||
.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
private async extractMentionedUsers(user: { host: MiUser['host']; }, tokens: mfm.MfmNode[]): Promise<MiUser[]> {
|
private async extractMentionedUsers(user: { host: MiUser['host']; }, tokens: mfm.MfmNode[]): Promise<MiUser[]> {
|
||||||
if (tokens == null) return [];
|
if (tokens == null) return [];
|
||||||
|
|
|
||||||
|
|
@ -141,14 +141,14 @@ export class NoteDeleteService {
|
||||||
|
|
||||||
if (!isPureRenote(note)) {
|
if (!isPureRenote(note)) {
|
||||||
// Decrement notes count (user)
|
// Decrement notes count (user)
|
||||||
promises.push(this.decNotesCountOfUser(user));
|
this.collapsedQueueService.updateUserQueue.enqueue(user.id, { additionalNotes: -1 });
|
||||||
}
|
}
|
||||||
|
|
||||||
this.collapsedQueueService.updateUserQueue.enqueue(user.id, { updatedAt: new Date() });
|
this.collapsedQueueService.updateUserQueue.enqueue(user.id, { updatedAt: new Date() });
|
||||||
|
|
||||||
for (const cascade of cascadingNotes) {
|
for (const cascade of cascadingNotes) {
|
||||||
if (!isPureRenote(cascade)) {
|
if (!isPureRenote(cascade)) {
|
||||||
promises.push(this.decNotesCountOfUser(cascade.user));
|
this.collapsedQueueService.updateUserQueue.enqueue(cascade.user.id, { additionalNotes: -1 });
|
||||||
}
|
}
|
||||||
// Don't mark cascaded user as updated (active)
|
// Don't mark cascaded user as updated (active)
|
||||||
}
|
}
|
||||||
|
|
@ -217,17 +217,6 @@ export class NoteDeleteService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
|
||||||
private async decNotesCountOfUser(user: { id: MiUser['id']; }) {
|
|
||||||
await this.usersRepository.createQueryBuilder().update()
|
|
||||||
.set({
|
|
||||||
updatedAt: this.timeService.date,
|
|
||||||
notesCount: () => '"notesCount" - 1',
|
|
||||||
})
|
|
||||||
.where('id = :id', { id: user.id })
|
|
||||||
.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
private async findCascadingNotes(note: MiNote): Promise<(MiNote & { user: MiUser })[]> {
|
private async findCascadingNotes(note: MiNote): Promise<(MiNote & { user: MiUser })[]> {
|
||||||
const cascadingNotes: MiNote[] = [];
|
const cascadingNotes: MiNote[] = [];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue