logs
This commit is contained in:
parent
1e7cbe9045
commit
3edfdc5e98
5 changed files with 67 additions and 37 deletions
|
@ -87,6 +87,8 @@ export type Source = {
|
|||
|
||||
reservedUsernames?: string[];
|
||||
|
||||
logLevel?: "error" | "warn" | "info" | "debug" | "trace";
|
||||
|
||||
// Managed hosting stuff
|
||||
maxUserSignups?: number;
|
||||
isManagedHosting?: boolean;
|
||||
|
|
|
@ -8,7 +8,7 @@ const logger = dbLogger.createSubLogger("meilisearch", "gray", false);
|
|||
logger.info("Connecting to Meilisearch");
|
||||
|
||||
const hasConfig =
|
||||
config.meilisearch && (config.meilisearch.host || config.meilisearch.port);
|
||||
config.meilisearch && (config.meilisearch.host || config.meilisearch.port);
|
||||
|
||||
const host = hasConfig ? config.meilisearch.host ?? "localhost" : "";
|
||||
const port = hasConfig ? config.meilisearch.port ?? 7700 : 0;
|
||||
|
@ -16,8 +16,8 @@ const ssl = hasConfig ? config.meilisearch.ssl ?? false : true;
|
|||
const apiKey = hasConfig ? config.meilisearch.apiKey ?? "" : "";
|
||||
|
||||
export default hasConfig
|
||||
? new MeiliSearch.MeiliSearch({
|
||||
host: `${ssl ? 'https' : 'http' }://${host}:${port}`,
|
||||
apiKey,
|
||||
})
|
||||
: null;
|
||||
? new MeiliSearch.MeiliSearch({
|
||||
host: `${ssl ? "https" : "http"}://${host}:${port}`,
|
||||
apiKey,
|
||||
})
|
||||
: null;
|
||||
|
|
|
@ -100,29 +100,34 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||
return await Notes.packMany(notes, me);
|
||||
} else if (meilisearch) {
|
||||
//search in meilisearch
|
||||
const result = await meilisearch.index("notes").search(ps.query, {
|
||||
limit: ps.limit,
|
||||
offset: ps.offset,
|
||||
filters: ps.userId
|
||||
? `userId = ${ps.userId}`
|
||||
: ps.channelId
|
||||
? `channelId = ${ps.channelId}`
|
||||
: undefined,
|
||||
});
|
||||
try {
|
||||
const result = await meilisearch.index("notes").search(ps.query, {
|
||||
limit: ps.limit,
|
||||
offset: ps.offset,
|
||||
filters: ps.userId,
|
||||
// ? `userId = ${ps.userId}`
|
||||
// : ps.channelId
|
||||
// ? `channelId = ${ps.channelId}`
|
||||
// : undefined,
|
||||
});
|
||||
|
||||
const ids = result.hits.map((hit) => hit.id);
|
||||
const ids = result.hits.map((hit: { id: string }) => hit.id);
|
||||
|
||||
// Fetch the notes from the database until we have enough to satisfy the limit
|
||||
const notes: Note[] = await Notes.find({
|
||||
where: {
|
||||
id: In(ids),
|
||||
},
|
||||
order: {
|
||||
id: "DESC",
|
||||
},
|
||||
});
|
||||
// Fetch the notes from the database until we have enough to satisfy the limit
|
||||
const notes: Note[] = await Notes.find({
|
||||
where: {
|
||||
id: In(ids),
|
||||
},
|
||||
order: {
|
||||
id: "DESC",
|
||||
},
|
||||
});
|
||||
|
||||
return await Notes.packMany(notes, me);
|
||||
return await Notes.packMany(notes, me);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return [];
|
||||
}
|
||||
} else if (sonic) {
|
||||
let start = 0;
|
||||
const chunkSize = 100;
|
||||
|
|
|
@ -60,6 +60,26 @@ export default class Logger {
|
|||
if (!this.store) store = false;
|
||||
if (level === "debug") store = false;
|
||||
|
||||
// filter out logs based on config log level
|
||||
if (config.logLevel === "error" && level !== "error") return;
|
||||
if (config.logLevel === "warn" && level !== "error" && level !== "warning")
|
||||
return;
|
||||
if (
|
||||
config.logLevel === "info" &&
|
||||
level !== "error" &&
|
||||
level !== "warning" &&
|
||||
level !== "info"
|
||||
)
|
||||
return;
|
||||
if (
|
||||
config.logLevel === "debug" &&
|
||||
level !== "error" &&
|
||||
level !== "warning" &&
|
||||
level !== "info" &&
|
||||
level !== "debug"
|
||||
)
|
||||
return;
|
||||
|
||||
if (this.parentLogger) {
|
||||
this.parentLogger.log(
|
||||
level,
|
||||
|
|
|
@ -779,19 +779,22 @@ export async function index(note: Note): Promise<void> {
|
|||
}
|
||||
|
||||
if (meilisearch) {
|
||||
await meilisearch.index("notes").addDocuments([
|
||||
await meilisearch.index("notes").addDocuments(
|
||||
[
|
||||
{
|
||||
id: note.id.toString(),
|
||||
text: note.text,
|
||||
userId: note.userId,
|
||||
userHost: note.userHost,
|
||||
channelId: note.channelId,
|
||||
cw: note.cw,
|
||||
createdAt: note.createdAt.getTime(),
|
||||
},
|
||||
],
|
||||
{
|
||||
id: note.id.toString(),
|
||||
text: note.text,
|
||||
userId: note.userId,
|
||||
userHost: note.userHost,
|
||||
channelId: note.channelId,
|
||||
cw: note.cw,
|
||||
createdAt: note.createdAt.getTime(),
|
||||
primaryKey: "id",
|
||||
},
|
||||
], {
|
||||
primaryKey: 'id',
|
||||
});
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue