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:
2025-11-02 08:38:05 -05:00
parent 70ca76835e
commit 0dc346d6b7
10 changed files with 943 additions and 73 deletions
+20 -4
View File
@@ -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
});