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 { scyllaQueries } from "@/db/cql.js";
|
||||||
import { notificationTypes } from "@/types.js";
|
import { notificationTypes } from "@/types.js";
|
||||||
|
|
||||||
|
export const scyllaLogger = new Logger("scylla");
|
||||||
|
|
||||||
function newClient(): Client | null {
|
function newClient(): Client | null {
|
||||||
if (!config.scylla) {
|
if (!config.scylla) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -38,26 +40,25 @@ function newClient(): Client | null {
|
||||||
credentials: config.scylla.credentials,
|
credentials: config.scylla.credentials,
|
||||||
});
|
});
|
||||||
|
|
||||||
const logger = new Logger("scylla");
|
|
||||||
client.on("log", (level, loggerName, message, _furtherInfo) => {
|
client.on("log", (level, loggerName, message, _furtherInfo) => {
|
||||||
const msg = `${loggerName} - ${message}`;
|
const msg = `${loggerName} - ${message}`;
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case "info":
|
case "info":
|
||||||
logger.info(msg);
|
scyllaLogger.info(msg);
|
||||||
break;
|
break;
|
||||||
case "warning":
|
case "warning":
|
||||||
logger.warn(msg);
|
scyllaLogger.warn(msg);
|
||||||
break;
|
break;
|
||||||
case "error":
|
case "error":
|
||||||
logger.error(msg);
|
scyllaLogger.error(msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
client.on("slow", (message) => {
|
client.on("slow", (message) => {
|
||||||
logger.warn(message);
|
scyllaLogger.warn(message);
|
||||||
});
|
});
|
||||||
client.on("large", (message) => {
|
client.on("large", (message) => {
|
||||||
logger.warn(message);
|
scyllaLogger.warn(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
|
|
|
@ -37,7 +37,12 @@ import {
|
||||||
} from "../index.js";
|
} from "../index.js";
|
||||||
import type { Instance } from "../entities/instance.js";
|
import type { Instance } from "../entities/instance.js";
|
||||||
import { userDenormalizedCache } from "@/services/user-cache.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 { UserNotePining } from "@/models/entities/user-note-pining.js";
|
||||||
import type { Note } from "@/models/entities/note.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));
|
}).then((notes) => notes.map(({ noteId }) => noteId));
|
||||||
|
|
||||||
if (pinnedNoteIds.length > 0) {
|
if (pinnedNoteIds.length > 0) {
|
||||||
if (scyllaClient) {
|
try {
|
||||||
const result = await scyllaClient.execute(
|
if (scyllaClient) {
|
||||||
prepared.note.select.byIds,
|
const result = await scyllaClient.execute(
|
||||||
[pinnedNoteIds],
|
prepared.note.select.byIds,
|
||||||
{ prepare: true },
|
[pinnedNoteIds],
|
||||||
);
|
{ prepare: true },
|
||||||
pinnedNotes = result.rows.map(parseScyllaNote);
|
);
|
||||||
} else {
|
pinnedNotes = result.rows.map(parseScyllaNote);
|
||||||
pinnedNotes = await Notes.findBy({ id: In(pinnedNoteIds) });
|
} 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