feat: add folder filtering and improve list view performance
- Added server-side folder filtering to paginated metadata endpoint with support for regular folders and .trash - Improved list view performance by optimizing kind filtering and non-markdown file handling - Updated folder navigation to properly reset other filters (tags, quick links, search) when selecting a folder - Added request ID tracking to prevent stale responses from affecting pagination state - Enhanced list view to show loading
This commit is contained in:
@@ -733,9 +733,25 @@ export function setupPaginatedMetadataEndpoint(app, metadataCache, performanceMo
|
||||
}
|
||||
);
|
||||
|
||||
// Paginate the cached result
|
||||
const paginatedItems = allMetadata.slice(cursor, cursor + limit);
|
||||
const hasMore = cursor + limit < allMetadata.length;
|
||||
// Optional server-side filtering by folder before paginating
|
||||
let filtered = allMetadata;
|
||||
const rawFolder = typeof req.query.folder === 'string' ? req.query.folder : '';
|
||||
const folder = String(rawFolder || '').toLowerCase().replace(/\\/g, '/').replace(/^\/+|\/+$/g, '');
|
||||
if (folder) {
|
||||
filtered = allMetadata.filter(it => {
|
||||
const fp = String(it.filePath || '').toLowerCase().replace(/\\/g, '/');
|
||||
if (!fp) return false;
|
||||
if (folder === '.trash') {
|
||||
return fp.startsWith('.trash/') || fp.includes('/.trash/');
|
||||
}
|
||||
const op = fp.replace(/^\/+|\/+$/g, '');
|
||||
return op === folder || op.startsWith(folder + '/');
|
||||
});
|
||||
}
|
||||
|
||||
// Paginate the filtered result
|
||||
const paginatedItems = filtered.slice(cursor, cursor + limit);
|
||||
const hasMore = cursor + limit < filtered.length;
|
||||
const nextCursor = hasMore ? cursor + limit : null;
|
||||
|
||||
performanceMonitor.markCache(hit);
|
||||
@@ -747,7 +763,7 @@ export function setupPaginatedMetadataEndpoint(app, metadataCache, performanceMo
|
||||
items: paginatedItems,
|
||||
nextCursor,
|
||||
hasMore,
|
||||
total: allMetadata.length,
|
||||
total: filtered.length,
|
||||
cached: hit,
|
||||
duration
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user