chore (backend): promise handling
This commit is contained in:
parent
195701d297
commit
a9bec190de
1 changed files with 20 additions and 17 deletions
|
@ -14,40 +14,47 @@ export async function scheduledNote(
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
logger.info(`Creating: ${job.data.noteId}`);
|
logger.info(`Creating: ${job.data.noteId}`);
|
||||||
|
|
||||||
const user = await Users.findOneBy({ id: job.data.user.id });
|
const [user, draftNote] = await Promise.all([
|
||||||
|
Users.findOneBy({ id: job.data.user.id }),
|
||||||
|
Notes.findOneBy({ id: job.data.noteId }),
|
||||||
|
]);
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
logger.warn(`User ${job.data.user.id} does not exist, aborting`);
|
logger.warn(`User ${job.data.user.id} does not exist, aborting`);
|
||||||
done();
|
done();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const draftNote = await Notes.findOneBy({ id: job.data.noteId });
|
|
||||||
if (draftNote == null) {
|
if (draftNote == null) {
|
||||||
logger.warn(`Note ${job.data.noteId} does not exist, aborting`);
|
logger.warn(`Note ${job.data.noteId} does not exist, aborting`);
|
||||||
done();
|
done();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const files = await DriveFiles.findBy({ id: In(draftNote.fileIds) });
|
|
||||||
|
|
||||||
if (user.isSuspended) {
|
if (user.isSuspended) {
|
||||||
logger.info(
|
logger.info(
|
||||||
`Cancelled due to user ${job.data.user.id} being suspended, aborting`,
|
`Cancelled due to user ${job.data.user.id} being suspended, aborting`,
|
||||||
);
|
);
|
||||||
deleteNote(user, draftNote);
|
await deleteNote(user, draftNote);
|
||||||
done();
|
done();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const visibleUsers = job.data.option.visibleUserIds
|
const [visibleUsers, reply, renote, files] = await Promise.all([
|
||||||
? await Users.findBy({
|
job.data.option.visibleUserIds
|
||||||
|
? Users.findBy({
|
||||||
id: In(job.data.option.visibleUserIds),
|
id: In(job.data.option.visibleUserIds),
|
||||||
})
|
})
|
||||||
: [];
|
: [],
|
||||||
|
|
||||||
const reply =
|
|
||||||
job.data.option.replyId != null
|
job.data.option.replyId != null
|
||||||
? await Notes.findOneBy({ id: job.data.option.replyId })
|
? Notes.findOneBy({ id: job.data.option.replyId })
|
||||||
: undefined;
|
: undefined,
|
||||||
|
job.data.option.renoteId != null
|
||||||
|
? Notes.findOneBy({ id: job.data.option.renoteId })
|
||||||
|
: undefined,
|
||||||
|
DriveFiles.findBy({ id: In(draftNote.fileIds) }),
|
||||||
|
]);
|
||||||
|
|
||||||
if (job.data.option.replyId != null && reply == null) {
|
if (job.data.option.replyId != null && reply == null) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
`Note ${job.data.option.replyId} (reply) does not exist, aborting`,
|
`Note ${job.data.option.replyId} (reply) does not exist, aborting`,
|
||||||
|
@ -56,10 +63,6 @@ export async function scheduledNote(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const renote =
|
|
||||||
job.data.option.renoteId != null
|
|
||||||
? await Notes.findOneBy({ id: job.data.option.renoteId })
|
|
||||||
: undefined;
|
|
||||||
if (job.data.option.renoteId != null && renote == null) {
|
if (job.data.option.renoteId != null && renote == null) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
`Note ${job.data.option.renoteId} (renote) does not exist, aborting`,
|
`Note ${job.data.option.renoteId} (renote) does not exist, aborting`,
|
||||||
|
|
Loading…
Reference in a new issue