mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-28 21:08:52 -07:00
Load relationships to populate user fields
This commit is contained in:
parent
e23ca84925
commit
f5aa0c86cf
2 changed files with 19 additions and 8 deletions
|
@ -4,6 +4,9 @@ import { dbLogger } from "./logger.js";
|
||||||
import config from "@/config/index.js";
|
import config from "@/config/index.js";
|
||||||
import {Note} from "@/models/entities/note.js";
|
import {Note} from "@/models/entities/note.js";
|
||||||
import * as url from "url";
|
import * as url from "url";
|
||||||
|
import {User} from "@/models/entities/user.js";
|
||||||
|
import {Users} from "@/models/index.js";
|
||||||
|
|
||||||
|
|
||||||
const logger = dbLogger.createSubLogger("meilisearch", "gray", false);
|
const logger = dbLogger.createSubLogger("meilisearch", "gray", false);
|
||||||
|
|
||||||
|
@ -98,14 +101,21 @@ export default hasConfig ? {
|
||||||
filter: constructedFilters
|
filter: constructedFilters
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
ingestNote: (note: Note | Note[]) => {
|
ingestNote: async (ingestNotes: Note | Note[]) => {
|
||||||
if (note instanceof Note) {
|
if (ingestNotes instanceof Note) {
|
||||||
note = [note];
|
ingestNotes = [ingestNotes];
|
||||||
}
|
}
|
||||||
|
|
||||||
let indexingBatch: MeilisearchNote[] = [];
|
let indexingBatch: MeilisearchNote[] = [];
|
||||||
|
|
||||||
note.forEach(note => {
|
for (let note of ingestNotes) {
|
||||||
|
if (note.user === undefined) {
|
||||||
|
let user = await Users.findOne({
|
||||||
|
where: {
|
||||||
|
id: note.userId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let attachmentType = "";
|
let attachmentType = "";
|
||||||
if (note.attachedFileTypes.length > 0) {
|
if (note.attachedFileTypes.length > 0) {
|
||||||
|
@ -129,11 +139,11 @@ export default hasConfig ? {
|
||||||
userHost: note.userHost !== "" ? note.userHost : url.parse(config.host).host,
|
userHost: note.userHost !== "" ? note.userHost : url.parse(config.host).host,
|
||||||
channelId: note.channelId ? note.channelId : "",
|
channelId: note.channelId ? note.channelId : "",
|
||||||
mediaAttachment: attachmentType,
|
mediaAttachment: attachmentType,
|
||||||
userName: note.user?.usernameLower ?? "UNKNOWN",
|
userName: note.user?.username ?? "UNKNOWN",
|
||||||
createdAt: note.createdAt.getTime() / 1000 // division by 1000 is necessary because Node returns in ms-accuracy
|
createdAt: note.createdAt.getTime() / 1000 // division by 1000 is necessary because Node returns in ms-accuracy
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
});
|
}
|
||||||
|
|
||||||
let indexingIDs = indexingBatch.map(note => note.id);
|
let indexingIDs = indexingBatch.map(note => note.id);
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ export default async function indexAllNotes(
|
||||||
order: {
|
order: {
|
||||||
id: 1,
|
id: 1,
|
||||||
},
|
},
|
||||||
|
relations: ["user"]
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error(`Failed to query notes ${e}`);
|
logger.error(`Failed to query notes ${e}`);
|
||||||
|
|
Loading…
Reference in a new issue