Optimize: Fetch only necessary fields from database

- Use Prisma select to fetch only colorPhotos and colorPhotosBack
- Reduces database transfer size by excluding unnecessary fields
- Cumulative improvements: 25.5s → 7.05s (72% overall speedup)
This commit is contained in:
Andymick
2026-07-19 12:19:45 +01:00
parent ca1da0bf07
commit 860f2c678d
2 changed files with 9 additions and 2 deletions
+2 -1
View File
@@ -104,7 +104,8 @@
"Bash(git commit -m 'Fix: Show Remove and Modify print area buttons for existing images *)", "Bash(git commit -m 'Fix: Show Remove and Modify print area buttons for existing images *)",
"Bash(git commit -m 'Fix: Handle image removal in product editor *)", "Bash(git commit -m 'Fix: Handle image removal in product editor *)",
"Bash(git commit -m 'Refactor: Move image display into PhotoPrintAreaField component *)", "Bash(git commit -m 'Refactor: Move image display into PhotoPrintAreaField component *)",
"Bash(git commit -m 'Optimize: Skip color photo processing when not uploading new photos *)" "Bash(git commit -m 'Optimize: Skip color photo processing when not uploading new photos *)",
"Bash(git commit -m 'Optimize: Fetch only necessary fields from database *)"
] ]
} }
} }
+7 -1
View File
@@ -201,7 +201,13 @@ export async function updateProduct(formData: FormData) {
.map((s) => s.trim()) .map((s) => s.trim())
.filter(Boolean); .filter(Boolean);
const existing = await prisma.product.findUnique({ where: { id } }); const existing = await prisma.product.findUnique({
where: { id },
select: {
colorPhotos: true,
colorPhotosBack: true,
},
});
if (!existing) throw new Error('Product not found.'); if (!existing) throw new Error('Product not found.');
// Only parse and process color photos if new ones were uploaded // Only parse and process color photos if new ones were uploaded