mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 22:09:16 +01:00
perf(database): ⚡ Improve performance when fetching timelines by fetching all data in a single SQL query
This commit is contained in:
parent
26dfd14aaf
commit
e48f57a3d8
24 changed files with 158 additions and 89 deletions
|
|
@ -62,6 +62,7 @@ export default (app: Hono) =>
|
|||
auth(meta.auth),
|
||||
async (context) => {
|
||||
const { id } = context.req.valid("param");
|
||||
const { user } = context.req.valid("header");
|
||||
|
||||
const otherUser = await User.fromId(id);
|
||||
|
||||
|
|
@ -95,6 +96,7 @@ export default (app: Hono) =>
|
|||
),
|
||||
limit,
|
||||
context.req.url,
|
||||
user?.id,
|
||||
);
|
||||
|
||||
return jsonResponse(
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ export default (app: Hono) =>
|
|||
),
|
||||
limit,
|
||||
context.req.url,
|
||||
user?.id,
|
||||
);
|
||||
|
||||
return jsonResponse(
|
||||
|
|
|
|||
|
|
@ -37,10 +37,14 @@ export default (app: Hono) =>
|
|||
if (!user) return errorResponse("Unauthorized", 401);
|
||||
|
||||
const notification = (
|
||||
await findManyNotifications({
|
||||
where: (notification, { eq }) => eq(notification.id, id),
|
||||
limit: 1,
|
||||
})
|
||||
await findManyNotifications(
|
||||
{
|
||||
where: (notification, { eq }) =>
|
||||
eq(notification.id, id),
|
||||
limit: 1,
|
||||
},
|
||||
user.id,
|
||||
)
|
||||
)[0];
|
||||
|
||||
if (!notification)
|
||||
|
|
|
|||
|
|
@ -174,6 +174,7 @@ export default (app: Hono) =>
|
|||
desc(notification.id),
|
||||
},
|
||||
context.req.raw,
|
||||
user.id,
|
||||
);
|
||||
|
||||
return jsonResponse(
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ export default (app: Hono) =>
|
|||
|
||||
const { user } = context.req.valid("header");
|
||||
|
||||
const foundStatus = await Note.fromId(id);
|
||||
const foundStatus = await Note.fromId(id, user?.id);
|
||||
|
||||
if (!foundStatus) return errorResponse("Record not found", 404);
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ export default (app: Hono) =>
|
|||
|
||||
if (!user) return errorResponse("Unauthorized", 401);
|
||||
|
||||
const note = await Note.fromId(id);
|
||||
const note = await Note.fromId(id, user?.id);
|
||||
|
||||
if (!note?.isViewableByUser(user))
|
||||
return errorResponse("Record not found", 404);
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ export default (app: Hono) =>
|
|||
|
||||
if (!user) return errorResponse("Unauthorized", 401);
|
||||
|
||||
const status = await Note.fromId(id);
|
||||
const status = await Note.fromId(id, user?.id);
|
||||
|
||||
if (!status?.isViewableByUser(user))
|
||||
return errorResponse("Record not found", 404);
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ export default (app: Hono) =>
|
|||
const { id } = context.req.valid("param");
|
||||
const { user } = context.req.valid("header");
|
||||
|
||||
const foundStatus = await Note.fromId(id);
|
||||
const foundStatus = await Note.fromId(id, user?.id);
|
||||
|
||||
if (!foundStatus?.isViewableByUser(user))
|
||||
return errorResponse("Record not found", 404);
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ export default (app: Hono) =>
|
|||
|
||||
if (!user) return errorResponse("Unauthorized", 401);
|
||||
|
||||
const foundStatus = await Note.fromId(id);
|
||||
const foundStatus = await Note.fromId(id, user?.id);
|
||||
|
||||
if (!foundStatus) return errorResponse("Record not found", 404);
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ export default (app: Hono) =>
|
|||
|
||||
if (!user) return errorResponse("Unauthorized", 401);
|
||||
|
||||
const foundStatus = await Note.fromId(id);
|
||||
const foundStatus = await Note.fromId(id, user.id);
|
||||
|
||||
if (!foundStatus?.isViewableByUser(user))
|
||||
return errorResponse("Record not found", 404);
|
||||
|
|
@ -72,7 +72,7 @@ export default (app: Hono) =>
|
|||
return errorResponse("Failed to reblog", 500);
|
||||
}
|
||||
|
||||
const finalNewReblog = await Note.fromId(newReblog.id);
|
||||
const finalNewReblog = await Note.fromId(newReblog.id, user?.id);
|
||||
|
||||
if (!finalNewReblog) {
|
||||
return errorResponse("Failed to reblog", 500);
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ export default (app: Hono) =>
|
|||
|
||||
if (!user) return errorResponse("Unauthorized", 401);
|
||||
|
||||
const status = await Note.fromId(id);
|
||||
const status = await Note.fromId(id, user.id);
|
||||
|
||||
if (!status?.isViewableByUser(user))
|
||||
return errorResponse("Record not found", 404);
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ export default (app: Hono) =>
|
|||
|
||||
if (!user) return errorResponse("Unauthorized", 401);
|
||||
|
||||
const status = await Note.fromId(id);
|
||||
const status = await Note.fromId(id, user.id);
|
||||
|
||||
if (!status?.isViewableByUser(user))
|
||||
return errorResponse("Record not found", 404);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ export default (app: Hono) =>
|
|||
|
||||
if (!user) return errorResponse("Unauthorized", 401);
|
||||
|
||||
const note = await Note.fromId(id);
|
||||
const note = await Note.fromId(id, user.id);
|
||||
|
||||
if (!note?.isViewableByUser(user))
|
||||
return errorResponse("Record not found", 404);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ export default (app: Hono) =>
|
|||
|
||||
if (!user) return errorResponse("Unauthorized", 401);
|
||||
|
||||
const status = await Note.fromId(id);
|
||||
const status = await Note.fromId(id, user.id);
|
||||
|
||||
if (!status) return errorResponse("Record not found", 404);
|
||||
|
||||
|
|
|
|||
|
|
@ -38,9 +38,7 @@ export default (app: Hono) =>
|
|||
|
||||
if (!user) return errorResponse("Unauthorized", 401);
|
||||
|
||||
if (!user) return errorResponse("Unauthorized", 401);
|
||||
|
||||
const foundStatus = await Note.fromId(id);
|
||||
const foundStatus = await Note.fromId(id, user.id);
|
||||
|
||||
// Check if user is authorized to view this status (if it's private)
|
||||
if (!foundStatus?.isViewableByUser(user))
|
||||
|
|
@ -51,6 +49,8 @@ export default (app: Hono) =>
|
|||
eq(Notes.authorId, user.id),
|
||||
eq(Notes.reblogId, foundStatus.getStatus().id),
|
||||
),
|
||||
undefined,
|
||||
user?.id,
|
||||
);
|
||||
|
||||
if (!existingReblog) {
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ export default (app: Hono) =>
|
|||
),
|
||||
limit,
|
||||
context.req.url,
|
||||
user.id,
|
||||
);
|
||||
|
||||
return jsonResponse(
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ export default (app: Hono) =>
|
|||
),
|
||||
limit,
|
||||
context.req.url,
|
||||
user?.id,
|
||||
);
|
||||
|
||||
return jsonResponse(
|
||||
|
|
|
|||
|
|
@ -186,6 +186,10 @@ export default (app: Hono) =>
|
|||
})`
|
||||
: undefined,
|
||||
),
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
self?.id,
|
||||
);
|
||||
|
||||
return jsonResponse({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue