feat: implement performance optimizations
- Add database indexes for frequently queried fields (listId, completed, priority, dueDate, createdAt) - Add compound indexes for common query patterns (listId+completed, listId+priority) - Implement pagination support in getItemsByFilter with configurable page size (default 50) - Optimize components with React.memo (ItemCard, ListCard, FilterPanel, SearchBar, SearchResults, EmptyState) - Configure Next.js for better bundle optimization: - Enable optimizePackageImports for lucide-react - Enable SWC minification - Remove console logs in production (except errors/warnings) - Optimize images with AVIF/WebP formats - Enable compression - Disable production source maps for smaller bundles - Loading states already implemented to prevent layout shift Task 18 complete - all performance optimizations implemented
This commit is contained in:
@@ -525,6 +525,8 @@ export async function getItemsByFilter(
|
||||
dueDateRange?: { start: Date | null; end: Date | null }
|
||||
sortBy?: 'createdAt' | 'dueDate' | 'priority' | 'title'
|
||||
sortOrder?: 'asc' | 'desc'
|
||||
page?: number
|
||||
pageSize?: number
|
||||
} = {}
|
||||
) {
|
||||
try {
|
||||
@@ -560,14 +562,26 @@ export async function getItemsByFilter(
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch items from database
|
||||
const items = await retryOperation(() =>
|
||||
prisma.item.findMany({
|
||||
where: whereClause,
|
||||
include: {
|
||||
list: true,
|
||||
},
|
||||
})
|
||||
// Pagination parameters
|
||||
const page = filters.page || 1
|
||||
const pageSize = filters.pageSize || 50
|
||||
const skip = (page - 1) * pageSize
|
||||
|
||||
// Fetch items from database with pagination
|
||||
const [items, totalCount] = await retryOperation(() =>
|
||||
Promise.all([
|
||||
prisma.item.findMany({
|
||||
where: whereClause,
|
||||
include: {
|
||||
list: true,
|
||||
},
|
||||
skip,
|
||||
take: pageSize,
|
||||
}),
|
||||
prisma.item.count({
|
||||
where: whereClause,
|
||||
}),
|
||||
])
|
||||
)
|
||||
|
||||
// Filter by tags (client-side since tags are stored as JSON)
|
||||
@@ -618,7 +632,16 @@ export async function getItemsByFilter(
|
||||
return sortOrder === 'asc' ? comparison : -comparison
|
||||
})
|
||||
|
||||
return sortedItems
|
||||
return {
|
||||
items: sortedItems,
|
||||
pagination: {
|
||||
page,
|
||||
pageSize,
|
||||
totalCount,
|
||||
totalPages: Math.ceil(totalCount / pageSize),
|
||||
hasMore: page * pageSize < totalCount,
|
||||
},
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error filtering items:', error)
|
||||
throw new Error('Failed to filter items. Please try again.')
|
||||
|
||||
Reference in New Issue
Block a user