further cleanup
This commit is contained in:
parent
98ffb20c6a
commit
2570f8a9eb
5 changed files with 46 additions and 12 deletions
|
@ -65,14 +65,11 @@ function newClient(): Client | null {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const scyllaClient = newClient();
|
export const scyllaClient = newClient();
|
||||||
|
|
||||||
export const prepared = scyllaQueries;
|
export const prepared = scyllaQueries;
|
||||||
|
|
||||||
const localPostCountCache = new Cache<number>("localPostCount", 1000 * 60 * 10);
|
const localPostCountCache = new Cache<number>("localPostCount", 1000 * 60 * 60);
|
||||||
export const allPostCountCache = new Cache<number>(
|
const allPostCountCache = new Cache<number>("allPostCount", 1000 * 60 * 60);
|
||||||
"allPostCount",
|
const reactionCountCache = new Cache<number>("reactionCount", 1000 * 60 * 60);
|
||||||
1000 * 60 * 10,
|
|
||||||
);
|
|
||||||
|
|
||||||
export async function fetchPostCount(local = false): Promise<number> {
|
export async function fetchPostCount(local = false): Promise<number> {
|
||||||
if (!scyllaClient) {
|
if (!scyllaClient) {
|
||||||
|
@ -94,6 +91,18 @@ export async function fetchPostCount(local = false): Promise<number> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function fetchReactionCount(): Promise<number> {
|
||||||
|
if (!scyllaClient) {
|
||||||
|
throw new Error("ScyllaDB is disabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
return await reactionCountCache.fetch(null, () =>
|
||||||
|
scyllaClient
|
||||||
|
.execute("SELECT COUNT(*) FROM reaction")
|
||||||
|
.then((result) => result.first().get("count") as number),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export interface ScyllaNotification {
|
export interface ScyllaNotification {
|
||||||
targetId: string;
|
targetId: string;
|
||||||
createdAtDate: Date;
|
createdAtDate: Date;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Instances, NoteReactions, Notes, Users } from "@/models/index.js";
|
import { Instances, NoteReactions } from "@/models/index.js";
|
||||||
import define from "../define.js";
|
import define from "../define.js";
|
||||||
import { driveChart, notesChart, usersChart } from "@/services/chart/index.js";
|
import { driveChart, notesChart, usersChart } from "@/services/chart/index.js";
|
||||||
import { IsNull } from "typeorm";
|
import { fetchReactionCount, scyllaClient } from "@/db/scylla.js";
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
requireCredential: false,
|
requireCredential: false,
|
||||||
|
@ -79,7 +79,7 @@ export default define(meta, paramDef, async () => {
|
||||||
//originalReactionsCount,
|
//originalReactionsCount,
|
||||||
instances,
|
instances,
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
NoteReactions.count({ cache: 3600000 }), // 1 hour
|
scyllaClient ? fetchReactionCount() : NoteReactions.count({ cache: 3600000 }), // 1 hour
|
||||||
//NoteReactions.count({ where: { userHost: IsNull() }, cache: 3600000 }),
|
//NoteReactions.count({ where: { userHost: IsNull() }, cache: 3600000 }),
|
||||||
Instances.count({ cache: 3600000 }),
|
Instances.count({ cache: 3600000 }),
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||||
import { Users, Notes } from "@/models/index.js";
|
import { Users, Notes } from "@/models/index.js";
|
||||||
import { IsNull } from "typeorm";
|
import { IsNull } from "typeorm";
|
||||||
import { MAX_NOTE_TEXT_LENGTH, FILE_TYPE_BROWSERSAFE } from "@/const.js";
|
import { MAX_NOTE_TEXT_LENGTH, FILE_TYPE_BROWSERSAFE } from "@/const.js";
|
||||||
import { fetchPostCount, scyllaClient } from "@/db/scylla";
|
import { fetchPostCount, scyllaClient } from "@/db/scylla.js";
|
||||||
|
|
||||||
export async function getInstance(
|
export async function getInstance(
|
||||||
response: Entity.Instance,
|
response: Entity.Instance,
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { Users, Notes } from "@/models/index.js";
|
||||||
import { IsNull, MoreThan } from "typeorm";
|
import { IsNull, MoreThan } from "typeorm";
|
||||||
import { MAX_NOTE_TEXT_LENGTH, MAX_CAPTION_TEXT_LENGTH } from "@/const.js";
|
import { MAX_NOTE_TEXT_LENGTH, MAX_CAPTION_TEXT_LENGTH } from "@/const.js";
|
||||||
import { Cache } from "@/misc/cache.js";
|
import { Cache } from "@/misc/cache.js";
|
||||||
import { fetchPostCount, scyllaClient } from "@/db/scylla";
|
import { fetchPostCount, scyllaClient } from "@/db/scylla.js";
|
||||||
|
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,12 @@ import {
|
||||||
import type { DriveFile } from "@/models/entities/drive-file.js";
|
import type { DriveFile } from "@/models/entities/drive-file.js";
|
||||||
import type { App } from "@/models/entities/app.js";
|
import type { App } from "@/models/entities/app.js";
|
||||||
import { Not, In } from "typeorm";
|
import { Not, In } from "typeorm";
|
||||||
import type { User, ILocalUser, IRemoteUser } from "@/models/entities/user.js";
|
import type {
|
||||||
|
User,
|
||||||
|
ILocalUser,
|
||||||
|
IRemoteUser,
|
||||||
|
CacheableUser,
|
||||||
|
} from "@/models/entities/user.js";
|
||||||
import { genId } from "@/misc/gen-id.js";
|
import { genId } from "@/misc/gen-id.js";
|
||||||
import {
|
import {
|
||||||
notesChart,
|
notesChart,
|
||||||
|
@ -75,6 +80,7 @@ import {
|
||||||
scyllaClient,
|
scyllaClient,
|
||||||
ScyllaPoll,
|
ScyllaPoll,
|
||||||
} from "@/db/scylla.js";
|
} from "@/db/scylla.js";
|
||||||
|
import { userByIdCache, userDenormalizedCache } from "../user-cache.js";
|
||||||
|
|
||||||
export const mutedWordsCache = new Cache<
|
export const mutedWordsCache = new Cache<
|
||||||
{ userId: UserProfile["userId"]; mutedWords: UserProfile["mutedWords"] }[]
|
{ userId: UserProfile["userId"]; mutedWords: UserProfile["mutedWords"] }[]
|
||||||
|
@ -1136,6 +1142,25 @@ function incNotesCountOfUser(user: { id: User["id"] }) {
|
||||||
})
|
})
|
||||||
.where("id = :id", { id: user.id })
|
.where("id = :id", { id: user.id })
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
userByIdCache.get(user.id).then((cache) => {
|
||||||
|
if (cache) {
|
||||||
|
const newUser: CacheableUser = {
|
||||||
|
...cache,
|
||||||
|
notesCount: cache.notesCount + 1,
|
||||||
|
};
|
||||||
|
userByIdCache.set(user.id, newUser);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
userDenormalizedCache.get(user.id).then((cache) => {
|
||||||
|
if (cache) {
|
||||||
|
const newUser: CacheableUser = {
|
||||||
|
...cache,
|
||||||
|
notesCount: cache.notesCount + 1,
|
||||||
|
};
|
||||||
|
userDenormalizedCache.set(user.id, newUser);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function extractMentionedUsers(
|
export async function extractMentionedUsers(
|
||||||
|
|
Loading…
Reference in a new issue