fix: mitigate pinned note error
This commit is contained in:
parent
7dd1d0ec4e
commit
3cf6c3731c
2 changed files with 30 additions and 16 deletions
|
@ -14,6 +14,8 @@ import type { UserProfile } from "@/models/entities/user-profile.js";
|
|||
import { scyllaQueries } from "@/db/cql.js";
|
||||
import { notificationTypes } from "@/types.js";
|
||||
|
||||
export const scyllaLogger = new Logger("scylla");
|
||||
|
||||
function newClient(): Client | null {
|
||||
if (!config.scylla) {
|
||||
return null;
|
||||
|
@ -38,26 +40,25 @@ function newClient(): Client | null {
|
|||
credentials: config.scylla.credentials,
|
||||
});
|
||||
|
||||
const logger = new Logger("scylla");
|
||||
client.on("log", (level, loggerName, message, _furtherInfo) => {
|
||||
const msg = `${loggerName} - ${message}`;
|
||||
switch (level) {
|
||||
case "info":
|
||||
logger.info(msg);
|
||||
scyllaLogger.info(msg);
|
||||
break;
|
||||
case "warning":
|
||||
logger.warn(msg);
|
||||
scyllaLogger.warn(msg);
|
||||
break;
|
||||
case "error":
|
||||
logger.error(msg);
|
||||
scyllaLogger.error(msg);
|
||||
break;
|
||||
}
|
||||
});
|
||||
client.on("slow", (message) => {
|
||||
logger.warn(message);
|
||||
scyllaLogger.warn(message);
|
||||
});
|
||||
client.on("large", (message) => {
|
||||
logger.warn(message);
|
||||
scyllaLogger.warn(message);
|
||||
});
|
||||
|
||||
return client;
|
||||
|
|
|
@ -37,7 +37,12 @@ import {
|
|||
} from "../index.js";
|
||||
import type { Instance } from "../entities/instance.js";
|
||||
import { userDenormalizedCache } from "@/services/user-cache.js";
|
||||
import { parseScyllaNote, prepared, scyllaClient } from "@/db/scylla.js";
|
||||
import {
|
||||
parseScyllaNote,
|
||||
prepared,
|
||||
scyllaClient,
|
||||
scyllaLogger,
|
||||
} from "@/db/scylla.js";
|
||||
import type { UserNotePining } from "@/models/entities/user-note-pining.js";
|
||||
import type { Note } from "@/models/entities/note.js";
|
||||
|
||||
|
@ -423,15 +428,23 @@ export const UserRepository = db.getRepository(User).extend({
|
|||
}).then((notes) => notes.map(({ noteId }) => noteId));
|
||||
|
||||
if (pinnedNoteIds.length > 0) {
|
||||
if (scyllaClient) {
|
||||
const result = await scyllaClient.execute(
|
||||
prepared.note.select.byIds,
|
||||
[pinnedNoteIds],
|
||||
{ prepare: true },
|
||||
);
|
||||
pinnedNotes = result.rows.map(parseScyllaNote);
|
||||
} else {
|
||||
pinnedNotes = await Notes.findBy({ id: In(pinnedNoteIds) });
|
||||
try {
|
||||
if (scyllaClient) {
|
||||
const result = await scyllaClient.execute(
|
||||
prepared.note.select.byIds,
|
||||
[pinnedNoteIds],
|
||||
{ prepare: true },
|
||||
);
|
||||
pinnedNotes = result.rows.map(parseScyllaNote);
|
||||
} else {
|
||||
pinnedNotes = await Notes.findBy({ id: In(pinnedNoteIds) });
|
||||
}
|
||||
} catch (e) {
|
||||
scyllaLogger.error("Failed to fetch pinned notes", {
|
||||
pinnedNoteIds,
|
||||
error: e,
|
||||
});
|
||||
pinnedNotes = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue