summaryrefslogtreecommitdiff
path: root/packages/backend/src
diff options
context:
space:
mode:
authortamaina <tamaina@hotmail.co.jp>2024-02-22 21:10:28 +0900
committerGitHub <noreply@github.com>2024-02-22 21:10:28 +0900
commit4d6fab06de2af01909cb37a54a407fda7f15f0bf (patch)
treead8f32bd1c87795fd7955bd7373aabc1de48887c /packages/backend/src
parentMerge branch 'develop' of https://github.com/misskey-dev/misskey into develop (diff)
downloadsharkey-4d6fab06de2af01909cb37a54a407fda7f15f0bf.tar.gz
sharkey-4d6fab06de2af01909cb37a54a407fda7f15f0bf.tar.bz2
sharkey-4d6fab06de2af01909cb37a54a407fda7f15f0bf.zip
refactor: Refactor NoteReadService.read (#13429)
* refactor: Refactor NoteReadService.read * clean up * Update packages/backend/src/core/NoteReadService.ts --------- Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com>
Diffstat (limited to 'packages/backend/src')
-rw-r--r--packages/backend/src/core/NoteReadService.ts61
-rw-r--r--packages/backend/src/server/api/endpoints/antennas/notes.ts4
2 files changed, 32 insertions, 33 deletions
diff --git a/packages/backend/src/core/NoteReadService.ts b/packages/backend/src/core/NoteReadService.ts
index feef024602..181c9f7649 100644
--- a/packages/backend/src/core/NoteReadService.ts
+++ b/packages/backend/src/core/NoteReadService.ts
@@ -88,46 +88,47 @@ export class NoteReadService implements OnApplicationShutdown {
userId: MiUser['id'],
notes: (MiNote | Packed<'Note'>)[],
): Promise<void> {
- const readMentions: (MiNote | Packed<'Note'>)[] = [];
- const readSpecifiedNotes: (MiNote | Packed<'Note'>)[] = [];
+ if (notes.length === 0) return;
+
+ const noteIds = new Set<MiNote['id']>();
for (const note of notes) {
if (note.mentions && note.mentions.includes(userId)) {
- readMentions.push(note);
+ noteIds.add(note.id);
} else if (note.visibleUserIds && note.visibleUserIds.includes(userId)) {
- readSpecifiedNotes.push(note);
+ noteIds.add(note.id);
}
}
- if ((readMentions.length > 0) || (readSpecifiedNotes.length > 0)) {
- // Remove the record
- await this.noteUnreadsRepository.delete({
- userId: userId,
- noteId: In([...readMentions.map(n => n.id), ...readSpecifiedNotes.map(n => n.id)]),
- });
+ if (noteIds.size === 0) return;
- // TODO: ↓まとめてクエリしたい
+ // Remove the record
+ await this.noteUnreadsRepository.delete({
+ userId: userId,
+ noteId: In(Array.from(noteIds)),
+ });
- trackPromise(this.noteUnreadsRepository.countBy({
- userId: userId,
- isMentioned: true,
- }).then(mentionsCount => {
- if (mentionsCount === 0) {
- // 全て既読になったイベントを発行
- this.globalEventService.publishMainStream(userId, 'readAllUnreadMentions');
- }
- }));
+ // TODO: ↓まとめてクエリしたい
- trackPromise(this.noteUnreadsRepository.countBy({
- userId: userId,
- isSpecified: true,
- }).then(specifiedCount => {
- if (specifiedCount === 0) {
- // 全て既読になったイベントを発行
- this.globalEventService.publishMainStream(userId, 'readAllUnreadSpecifiedNotes');
- }
- }));
- }
+ trackPromise(this.noteUnreadsRepository.countBy({
+ userId: userId,
+ isMentioned: true,
+ }).then(mentionsCount => {
+ if (mentionsCount === 0) {
+ // 全て既読になったイベントを発行
+ this.globalEventService.publishMainStream(userId, 'readAllUnreadMentions');
+ }
+ }));
+
+ trackPromise(this.noteUnreadsRepository.countBy({
+ userId: userId,
+ isSpecified: true,
+ }).then(specifiedCount => {
+ if (specifiedCount === 0) {
+ // 全て既読になったイベントを発行
+ this.globalEventService.publishMainStream(userId, 'readAllUnreadSpecifiedNotes');
+ }
+ }));
}
@bindThis
diff --git a/packages/backend/src/server/api/endpoints/antennas/notes.ts b/packages/backend/src/server/api/endpoints/antennas/notes.ts
index 39f3fab21e..f4dfe1ecc4 100644
--- a/packages/backend/src/server/api/endpoints/antennas/notes.ts
+++ b/packages/backend/src/server/api/endpoints/antennas/notes.ts
@@ -124,9 +124,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
notes.sort((a, b) => a.id > b.id ? -1 : 1);
}
- if (notes.length > 0) {
- this.noteReadService.read(me.id, notes);
- }
+ this.noteReadService.read(me.id, notes);
return await this.noteEntityService.packMany(notes, me);
});