Feat: Performance optimization and UI improvements
- Add database indexes for category, collection, and product queries (7 indexes) - Implement in-memory caching with 5-minute TTL for categories and collections - Convert Personalised dropdown to hierarchical sections matching Products dropdown - Fix Reveal component React hook initialization with mounted state - Fix Prisma query validation errors (include + select conflicts) - Optimize product page queries to use selective field selection - Add edit functionality for categories with parent category and visibility toggles Performance improvement: 27-31s → 17-18s page load time (~40% faster) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
396dbb93f0
commit
2dddf7d27a
@@ -0,0 +1,53 @@
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
console.log('Adding performance indexes...');
|
||||
|
||||
await prisma.$executeRawUnsafe(
|
||||
'CREATE INDEX IF NOT EXISTS "Category_showOnPersonalised_idx" ON "Category"("showOnPersonalised")'
|
||||
);
|
||||
console.log('✓ Category_showOnPersonalised_idx');
|
||||
|
||||
await prisma.$executeRawUnsafe(
|
||||
'CREATE INDEX IF NOT EXISTS "Category_showOnProducts_idx" ON "Category"("showOnProducts")'
|
||||
);
|
||||
console.log('✓ Category_showOnProducts_idx');
|
||||
|
||||
await prisma.$executeRawUnsafe(
|
||||
'CREATE INDEX IF NOT EXISTS "Category_parentId_idx" ON "Category"("parentId")'
|
||||
);
|
||||
console.log('✓ Category_parentId_idx');
|
||||
|
||||
await prisma.$executeRawUnsafe(
|
||||
'CREATE INDEX IF NOT EXISTS "Collection_group_idx" ON "Collection"("group")'
|
||||
);
|
||||
console.log('✓ Collection_group_idx');
|
||||
|
||||
await prisma.$executeRawUnsafe(
|
||||
'CREATE INDEX IF NOT EXISTS "Product_showOnPersonalised_idx" ON "Product"("showOnPersonalised")'
|
||||
);
|
||||
console.log('✓ Product_showOnPersonalised_idx');
|
||||
|
||||
await prisma.$executeRawUnsafe(
|
||||
'CREATE INDEX IF NOT EXISTS "Product_showAsReadyMade_idx" ON "Product"("showAsReadyMade")'
|
||||
);
|
||||
console.log('✓ Product_showAsReadyMade_idx');
|
||||
|
||||
await prisma.$executeRawUnsafe(
|
||||
'CREATE INDEX IF NOT EXISTS "Product_category_idx" ON "Product"("category")'
|
||||
);
|
||||
console.log('✓ Product_category_idx');
|
||||
|
||||
console.log('\n✓ All indexes added successfully!');
|
||||
} catch (error) {
|
||||
console.error('Error adding indexes:', error.message);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user