From 3273adaaa1381fcf9c8860241be17d6804bb6be6 Mon Sep 17 00:00:00 2001 From: Namekuji Date: Mon, 4 Sep 2023 22:49:12 -0400 Subject: [PATCH] remove counts --- .../src/queue/processors/background/index-all-notes.ts | 7 ++++++- packages/backend/src/server/api/mastodon/endpoints/meta.ts | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/queue/processors/background/index-all-notes.ts b/packages/backend/src/queue/processors/background/index-all-notes.ts index c0275b420a..67f1ae14ff 100644 --- a/packages/backend/src/queue/processors/background/index-all-notes.ts +++ b/packages/backend/src/queue/processors/background/index-all-notes.ts @@ -7,6 +7,7 @@ import { MoreThan } from "typeorm"; import { index } from "@/services/note/create.js"; import { Note } from "@/models/entities/note.js"; import meilisearch from "../../../db/meilisearch.js"; +import { scyllaClient } from "@/db/scylla.js"; const logger = queueLogger.createSubLogger("index-all-notes"); @@ -55,7 +56,11 @@ export default async function indexAllNotes( } try { - const count = await Notes.count(); + const count = await (scyllaClient + ? scyllaClient + .execute("SELECT COUNT(1) FROM note") + .then((result) => result.first().get("count") as number) + : Notes.count()); total = count; await job.update({ indexedCount, cursor, total }); } catch (e) {} diff --git a/packages/backend/src/server/api/mastodon/endpoints/meta.ts b/packages/backend/src/server/api/mastodon/endpoints/meta.ts index c7dd6181fb..5872ae4a49 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/meta.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/meta.ts @@ -4,6 +4,7 @@ import { fetchMeta } from "@/misc/fetch-meta.js"; import { Users, Notes } from "@/models/index.js"; import { IsNull } from "typeorm"; import { MAX_NOTE_TEXT_LENGTH, FILE_TYPE_BROWSERSAFE } from "@/const.js"; +import { scyllaClient } from "@/db/scylla"; export async function getInstance( response: Entity.Instance, @@ -12,7 +13,11 @@ export async function getInstance( const [meta, totalUsers, totalStatuses] = await Promise.all([ fetchMeta(true), Users.count({ where: { host: IsNull() } }), - Notes.count({ where: { userHost: IsNull() } }), + scyllaClient + ? scyllaClient + .execute("SELECT COUNT(1) FROM note") + .then((result) => result.first().get("count") as number) + : Notes.count({ where: { userHost: IsNull() } }), ]); return {