Fixed bug where post count was string; not number

This commit is contained in:
Sal Rahman 2023-10-10 19:12:21 +00:00 committed by Kainoa Kanter
parent 7f9283127b
commit c61ad010d7

View file

@ -4,9 +4,7 @@ import type { Note } from "@/models/entities/note.js";
import type { NoteReaction } from "@/models/entities/note-reaction.js"; import type { NoteReaction } from "@/models/entities/note-reaction.js";
import { Client, types, tracker } from "cassandra-driver"; import { Client, types, tracker } from "cassandra-driver";
import type { User } from "@/models/entities/user.js"; import type { User } from "@/models/entities/user.js";
import { import { Cache } from "@/misc/cache.js";
Cache,
} from "@/misc/cache.js";
import { getTimestamp } from "@/misc/gen-id.js"; import { getTimestamp } from "@/misc/gen-id.js";
import Logger from "@/services/logger.js"; import Logger from "@/services/logger.js";
import { getWordHardMute } from "@/misc/check-word-mute.js"; import { getWordHardMute } from "@/misc/check-word-mute.js";
@ -34,7 +32,8 @@ function newClient(): Client | null {
[types.distance.local]: config.scylla.connections?.local || 2, [types.distance.local]: config.scylla.connections?.local || 2,
[types.distance.remote]: config.scylla.connections?.remote || 1, [types.distance.remote]: config.scylla.connections?.remote || 1,
}, },
maxRequestsPerConnection: config.scylla.connections?.maxRequestsPerConnection || 2048, maxRequestsPerConnection:
config.scylla.connections?.maxRequestsPerConnection || 2048,
}, },
requestTracker, requestTracker,
credentials: config.scylla.credentials, credentials: config.scylla.credentials,
@ -82,14 +81,16 @@ export async function fetchPostCount(local = false): Promise<number> {
.execute("SELECT COUNT(*) FROM local_note_by_user_id", [], { .execute("SELECT COUNT(*) FROM local_note_by_user_id", [], {
prepare: true, prepare: true,
}) })
.then((result) => result.first().get("count") as number), .then((result) => result.first().get("count"))
.then(Number),
); );
} }
return await allPostCountCache.fetch(null, () => return await allPostCountCache.fetch(null, () =>
scyllaClient scyllaClient
.execute("SELECT COUNT(*) FROM note", [], { prepare: true }) .execute("SELECT COUNT(*) FROM note", [], { prepare: true })
.then((result) => result.first().get("count") as number), .then((result) => result.first().get("count"))
.then(Number),
); );
} }
@ -101,7 +102,8 @@ export async function fetchReactionCount(): Promise<number> {
return await reactionCountCache.fetch(null, () => return await reactionCountCache.fetch(null, () =>
scyllaClient scyllaClient
.execute("SELECT COUNT(*) FROM reaction", [], { prepare: true }) .execute("SELECT COUNT(*) FROM reaction", [], { prepare: true })
.then((result) => result.first().get("count") as number), .then((result) => result.first().get("count"))
.then(Number),
); );
} }
@ -112,7 +114,7 @@ export interface ScyllaNotification {
id: string; id: string;
notifierId: string | null; notifierId: string | null;
notifierHost: string | null; notifierHost: string | null;
type: typeof notificationTypes[number]; type: (typeof notificationTypes)[number];
entityId: string | null; entityId: string | null;
reaction: string | null; reaction: string | null;
choice: number | null; choice: number | null;
@ -462,7 +464,8 @@ export async function execPaginationQuery(
params.push(sinceDate); params.push(sinceDate);
} }
const fetchLimit = kind === "list" ? Math.min(ps.limit, queryLimit) : queryLimit; const fetchLimit =
kind === "list" ? Math.min(ps.limit, queryLimit) : queryLimit;
params.push(fetchLimit); params.push(fetchLimit);
const result = await scyllaClient.execute(query, params, { const result = await scyllaClient.execute(query, params, {
@ -612,9 +615,7 @@ export function filterMutedNote(
mutedWords: string[][], mutedWords: string[][],
): ScyllaNote[] { ): ScyllaNote[] {
if (mutedWords.length > 0) { if (mutedWords.length > 0) {
return notes.filter( return notes.filter((note) => !getWordHardMute(note, user, mutedWords));
(note) => !getWordHardMute(note, user, mutedWords),
);
} }
return notes; return notes;