Add getAllFromIndex method for efficient sorted queries
- Add getAllFromIndex to StorageBackend interface for index-based queries - Implement getAllFromIndex in IndexedDBStorageBackend using cursor API - Update SessionsStore.getAllMetadata to use lastModified index - Enables database-native sorting instead of fetching all keys and sorting in JS Benefits: - Much faster for large datasets (uses IndexedDB cursor with direction) - Reduces memory usage (no need to load all keys first) - Leverages existing indices for optimal performance
This commit is contained in:
@@ -42,11 +42,8 @@ export class SessionsStore extends Store {
|
||||
}
|
||||
|
||||
async getAllMetadata(): Promise<SessionMetadata[]> {
|
||||
const keys = await this.getBackend().keys("sessions-metadata");
|
||||
const metadata = await Promise.all(
|
||||
keys.map((key) => this.getBackend().get<SessionMetadata>("sessions-metadata", key)),
|
||||
);
|
||||
return metadata.filter((m): m is SessionMetadata => m !== null);
|
||||
// Use the lastModified index to get sessions sorted by most recent first
|
||||
return this.getBackend().getAllFromIndex<SessionMetadata>("sessions-metadata", "lastModified", "desc");
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user