From ed26870807d80db1750da57370b5ca7427562abf Mon Sep 17 00:00:00 2001 From: Namekuji Date: Wed, 30 Aug 2023 14:50:15 -0400 Subject: [PATCH] fix: remove notes count --- .../server/api/endpoints/channels/follow.ts | 2 +- .../src/server/api/stream/channels/channel.ts | 3 ++- packages/backend/src/services/note/create.ts | 22 ++++++++++--------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/channels/follow.ts b/packages/backend/src/server/api/endpoints/channels/follow.ts index b2e1907fa0..f9ce79321b 100644 --- a/packages/backend/src/server/api/endpoints/channels/follow.ts +++ b/packages/backend/src/server/api/endpoints/channels/follow.ts @@ -35,7 +35,7 @@ export default define(meta, paramDef, async (ps, user) => { id: ps.channelId, }); - if (channel == null) { + if (!channel) { throw new ApiError(meta.errors.noSuchChannel); } diff --git a/packages/backend/src/server/api/stream/channels/channel.ts b/packages/backend/src/server/api/stream/channels/channel.ts index 2ff4e08209..ed80b9fb35 100644 --- a/packages/backend/src/server/api/stream/channels/channel.ts +++ b/packages/backend/src/server/api/stream/channels/channel.ts @@ -4,6 +4,7 @@ import { isUserRelated } from "@/misc/is-user-related.js"; import type { User } from "@/models/entities/user.js"; import type { StreamMessages } from "../types.js"; import type { Packed } from "@/misc/schema.js"; +import { scyllaClient } from "@/db/scylla.js"; export default class extends Channel { public readonly chName = "channel"; @@ -45,7 +46,7 @@ export default class extends Channel { } private onEvent(data: StreamMessages["channel"]["payload"]) { - if (data.type === "typing") { + if (data.type === "typing" && !scyllaClient) { const id = data.body; const begin = !this.typers.has(id); this.typers.set(id, new Date()); diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index 438be25aaf..c70722c8c3 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -651,16 +651,18 @@ export default async ( lastNotedAt: new Date(), }); - await Notes.countBy({ - userId: user.id, - channelId: data.channel.id, - }).then((count) => { - // この処理が行われるのはノート作成後なので、ノートが一つしかなかったら最初の投稿だと判断できる - // TODO: とはいえノートを削除して何回も投稿すればその分だけインクリメントされる雑さもあるのでどうにかしたい - if (count === 1 && data.channel != null) { - Channels.increment({ id: data.channel.id }, "usersCount", 1); - } - }); + if (!scyllaClient) { + await Notes.countBy({ + userId: user.id, + channelId: data.channel.id, + }).then((count) => { + // この処理が行われるのはノート作成後なので、ノートが一つしかなかったら最初の投稿だと判断できる + // TODO: とはいえノートを削除して何回も投稿すればその分だけインクリメントされる雑さもあるのでどうにかしたい + if (count === 1 && data.channel != null) { + Channels.increment({ id: data.channel.id }, "usersCount", 1); + } + }); + } } // Register to search database