rename additionalNotes to notesCountDelta

This commit is contained in:
Hazelnoot 2025-06-25 13:32:11 -04:00
parent e7ea4a3ba2
commit 2fd44d68c5
4 changed files with 14 additions and 13 deletions

View file

@ -14,24 +14,25 @@ import { bindThis } from '@/decorators.js';
import type { MiInstance } from '@/models/Instance.js';
import { InternalEventService } from '@/core/InternalEventService.js';
import { MiUser } from '@/models/User.js';
import type { UsersRepository } from '@/models/_.js';
import type { MiNote, UsersRepository } from '@/models/_.js';
import { DI } from '@/di-symbols.js';
export type UpdateInstanceJob = {
latestRequestReceivedAt?: Date,
shouldUnsuspend?: boolean,
additionalNotes?: number,
notesCountDelta?: number,
};
export type UpdateUserJob = {
updatedAt?: Date,
additionalNotes?: number,
notesCountDelta?: number,
};
@Injectable()
export class CollapsedQueueService implements OnApplicationShutdown {
// Moved from InboxProcessorService to allow access from ApInboxService
// Moved from InboxProcessorService
public readonly updateInstanceQueue: CollapsedQueue<MiInstance['id'], UpdateInstanceJob>;
// Moved from NoteCreateService, NoteEditService, and NoteDeleteService
public readonly updateUserQueue: CollapsedQueue<MiUser['id'], UpdateUserJob>;
private readonly logger: Logger;
@ -57,13 +58,13 @@ export class CollapsedQueueService implements OnApplicationShutdown {
(oldJob, newJob) => ({
latestRequestReceivedAt: maxDate(oldJob.latestRequestReceivedAt, newJob.latestRequestReceivedAt),
shouldUnsuspend: oldJob.shouldUnsuspend || newJob.shouldUnsuspend,
additionalNotes: (oldJob.additionalNotes ?? 0) + (newJob.additionalNotes ?? 0),
notesCountDelta: (oldJob.notesCountDelta ?? 0) + (newJob.notesCountDelta ?? 0),
}),
(id, job) => this.federatedInstanceService.update(id, {
latestRequestReceivedAt: job.latestRequestReceivedAt,
isNotResponding: job.latestRequestReceivedAt ? false : undefined,
suspensionState: job.shouldUnsuspend ? 'none' : undefined,
notesCount: job.additionalNotes ? () => `"notesCount" + ${job.additionalNotes}` : undefined,
notesCount: job.notesCountDelta ? () => `"notesCount" + ${job.notesCountDelta}` : undefined,
}),
{
onError: this.onQueueError,
@ -76,11 +77,11 @@ export class CollapsedQueueService implements OnApplicationShutdown {
oneMinuteInterval,
(oldJob, newJob) => ({
updatedAt: maxDate(oldJob.updatedAt, newJob.updatedAt),
additionalNotes: (oldJob.additionalNotes ?? 0) + (newJob.additionalNotes ?? 0),
notesCountDelta: (oldJob.notesCountDelta ?? 0) + (newJob.notesCountDelta ?? 0),
}),
(id, job) => this.usersRepository.update({ id }, {
updatedAt: job.updatedAt,
notesCount: job.additionalNotes ? () => `"notesCount" + ${job.additionalNotes}` : undefined,
notesCount: job.notesCountDelta ? () => `"notesCount" + ${job.notesCountDelta}` : undefined,
}),
{
onError: this.onQueueError,

View file

@ -587,7 +587,7 @@ export class NoteCreateService implements OnApplicationShutdown {
if (isRemoteUser(user)) {
this.federatedInstanceService.fetchOrRegister(user.host).then(async i => {
if (!this.isRenote(note) || this.isQuote(note)) {
this.collapsedQueueService.updateInstanceQueue.enqueue(i.id, { additionalNotes: 1 });
this.collapsedQueueService.updateInstanceQueue.enqueue(i.id, { notesCountDelta: 1 });
}
if (this.meta.enableChartsForFederatedInstances) {
this.instanceChart.updateNote(i.host, note, true);
@ -605,7 +605,7 @@ export class NoteCreateService implements OnApplicationShutdown {
if (!this.isRenote(note) || this.isQuote(note)) {
// Increment notes count (user)
this.collapsedQueueService.updateUserQueue.enqueue(user.id, { additionalNotes: 1 });
this.collapsedQueueService.updateUserQueue.enqueue(user.id, { notesCountDelta: 1 });
}
this.collapsedQueueService.updateUserQueue.enqueue(user.id, { updatedAt: new Date() });

View file

@ -141,14 +141,14 @@ export class NoteDeleteService {
if (!isPureRenote(note)) {
// Decrement notes count (user)
this.collapsedQueueService.updateUserQueue.enqueue(user.id, { additionalNotes: -1 });
this.collapsedQueueService.updateUserQueue.enqueue(user.id, { notesCountDelta: -1 });
}
this.collapsedQueueService.updateUserQueue.enqueue(user.id, { updatedAt: new Date() });
for (const cascade of cascadingNotes) {
if (!isPureRenote(cascade)) {
this.collapsedQueueService.updateUserQueue.enqueue(cascade.user.id, { additionalNotes: -1 });
this.collapsedQueueService.updateUserQueue.enqueue(cascade.user.id, { notesCountDelta: -1 });
}
// Don't mark cascaded user as updated (active)
}

View file

@ -616,7 +616,7 @@ export class NoteEditService implements OnApplicationShutdown {
if (isRemoteUser(user)) {
this.federatedInstanceService.fetchOrRegister(user.host).then(async i => {
if (note.renote && note.text || !note.renote) {
this.collapsedQueueService.updateInstanceQueue.enqueue(i.id, { additionalNotes: 1 });
this.collapsedQueueService.updateInstanceQueue.enqueue(i.id, { notesCountDelta: 1 });
}
if (this.meta.enableChartsForFederatedInstances) {
this.instanceChart.updateNote(i.host, note, true);