use redis
This commit is contained in:
parent
0c9cce7c7c
commit
6236661d62
1 changed files with 16 additions and 15 deletions
|
@ -69,11 +69,11 @@ import { db } from "@/db/postgre.js";
|
||||||
import { getActiveWebhooks } from "@/misc/webhook-cache.js";
|
import { getActiveWebhooks } from "@/misc/webhook-cache.js";
|
||||||
import { shouldSilenceInstance } from "@/misc/should-block-instance.js";
|
import { shouldSilenceInstance } from "@/misc/should-block-instance.js";
|
||||||
import meilisearch from "../../db/meilisearch.js";
|
import meilisearch from "../../db/meilisearch.js";
|
||||||
|
import { redisClient } from "@/db/redis.js";
|
||||||
|
|
||||||
const mutedWordsCache = new Cache<
|
const mutedWordsCache = new Cache<
|
||||||
{ userId: UserProfile["userId"]; mutedWords: UserProfile["mutedWords"] }[]
|
{ userId: UserProfile["userId"]; mutedWords: UserProfile["mutedWords"] }[]
|
||||||
>(1000 * 60 * 5);
|
>(1000 * 60 * 5);
|
||||||
const publishedNoteCache = new Cache<boolean>(1000 * 10);
|
|
||||||
|
|
||||||
type NotificationType = "reply" | "renote" | "quote" | "mention";
|
type NotificationType = "reply" | "renote" | "quote" | "mention";
|
||||||
|
|
||||||
|
@ -457,27 +457,28 @@ export default async (
|
||||||
|
|
||||||
if (!dontFederateInitially) {
|
if (!dontFederateInitially) {
|
||||||
const relays = await getCachedRelays();
|
const relays = await getCachedRelays();
|
||||||
|
const boostedByRelay =
|
||||||
|
!!user.inbox &&
|
||||||
|
relays.map((relay) => relay.inbox).includes(user.inbox);
|
||||||
|
|
||||||
if (!note.uri) {
|
if (!note.uri) {
|
||||||
publishNotesStream(note);
|
publishNotesStream(note);
|
||||||
} else if (
|
} else if (
|
||||||
|
boostedByRelay &&
|
||||||
data.renote?.uri &&
|
data.renote?.uri &&
|
||||||
publishedNoteCache.get(data.renote.uri) !== true &&
|
(await redisClient.exists(`publishedNote:${data.renote.uri}`)) === 0
|
||||||
user.inbox &&
|
|
||||||
relays.map((relay) => relay.inbox).includes(user.inbox)
|
|
||||||
) {
|
) {
|
||||||
const uri = data.renote.uri;
|
|
||||||
publishNotesStream(data.renote);
|
publishNotesStream(data.renote);
|
||||||
publishedNoteCache.set(uri, true);
|
const key = `publishedNote:${data.renote.uri}`;
|
||||||
setTimeout(() => {
|
await redisClient.set(key, 1, "EX", 10);
|
||||||
publishedNoteCache.delete(uri);
|
} else if (
|
||||||
}, 1000 * 10);
|
!boostedByRelay &&
|
||||||
} else if (note.uri && publishedNoteCache.get(note.uri) !== true) {
|
note.uri &&
|
||||||
const uri = note.uri;
|
(await redisClient.exists(`publishedNote:${note.uri}`)) === 0
|
||||||
|
) {
|
||||||
|
const key = `publishedNote:${note.uri}`;
|
||||||
publishNotesStream(note);
|
publishNotesStream(note);
|
||||||
publishedNoteCache.set(uri, true);
|
await redisClient.set(key, 1, "EX", 10);
|
||||||
setTimeout(() => {
|
|
||||||
publishedNoteCache.delete(uri);
|
|
||||||
}, 1000 * 10);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (note.replyId != null) {
|
if (note.replyId != null) {
|
||||||
|
|
Loading…
Reference in a new issue