mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 08:06:56 +00:00
카테고리 페이지에서의 네트워크 호출 최적화
This commit is contained in:
@@ -9,6 +9,7 @@ const categoryRouter = router({
|
||||
.input(
|
||||
z.object({
|
||||
id: categoryIdSchema,
|
||||
recurse: z.boolean().default(false),
|
||||
}),
|
||||
)
|
||||
.query(async ({ ctx, input }) => {
|
||||
@@ -20,7 +21,12 @@ const categoryRouter = router({
|
||||
throw new TRPCError({ code: "NOT_FOUND", message: "Invalid category id" });
|
||||
}
|
||||
|
||||
const categories = await CategoryRepo.getAllCategoriesByParent(ctx.session.userId, input.id);
|
||||
const [categories, files] = await Promise.all([
|
||||
CategoryRepo.getAllCategoriesByParent(ctx.session.userId, input.id),
|
||||
input.id !== "root"
|
||||
? FileRepo.getAllFilesByCategory(ctx.session.userId, input.id, input.recurse)
|
||||
: undefined,
|
||||
]);
|
||||
return {
|
||||
metadata: category && {
|
||||
parent: category.parentId,
|
||||
@@ -30,7 +36,28 @@ const categoryRouter = router({
|
||||
name: category.encName.ciphertext,
|
||||
nameIv: category.encName.iv,
|
||||
},
|
||||
subCategories: categories.map(({ id }) => id),
|
||||
subCategories: categories.map((category) => ({
|
||||
id: category.id,
|
||||
mekVersion: category.mekVersion,
|
||||
dek: category.encDek,
|
||||
dekVersion: category.dekVersion,
|
||||
name: category.encName.ciphertext,
|
||||
nameIv: category.encName.iv,
|
||||
})),
|
||||
files: files?.map((file) => ({
|
||||
id: file.id,
|
||||
mekVersion: file.mekVersion,
|
||||
dek: file.encDek,
|
||||
dekVersion: file.dekVersion,
|
||||
contentType: file.contentType,
|
||||
name: file.encName.ciphertext,
|
||||
nameIv: file.encName.iv,
|
||||
createdAt: file.encCreatedAt?.ciphertext,
|
||||
createdAtIv: file.encCreatedAt?.iv,
|
||||
lastModifiedAt: file.encLastModifiedAt.ciphertext,
|
||||
lastModifiedAtIv: file.encLastModifiedAt.iv,
|
||||
isRecursive: file.isRecursive,
|
||||
})),
|
||||
};
|
||||
}),
|
||||
|
||||
@@ -113,27 +140,6 @@ const categoryRouter = router({
|
||||
}
|
||||
}),
|
||||
|
||||
files: roleProcedure["activeClient"]
|
||||
.input(
|
||||
z.object({
|
||||
id: z.int().positive(),
|
||||
recurse: z.boolean().default(false),
|
||||
}),
|
||||
)
|
||||
.query(async ({ ctx, input }) => {
|
||||
const category = await CategoryRepo.getCategory(ctx.session.userId, input.id);
|
||||
if (!category) {
|
||||
throw new TRPCError({ code: "NOT_FOUND", message: "Invalid category id" });
|
||||
}
|
||||
|
||||
const files = await FileRepo.getAllFilesByCategory(
|
||||
ctx.session.userId,
|
||||
input.id,
|
||||
input.recurse,
|
||||
);
|
||||
return files.map(({ id, isRecursive }) => ({ file: id, isRecursive }));
|
||||
}),
|
||||
|
||||
addFile: roleProcedure["activeClient"]
|
||||
.input(
|
||||
z.object({
|
||||
|
||||
Reference in New Issue
Block a user