implement loading all members

This commit is contained in:
Bruno Windels 2020-08-19 16:13:30 +02:00
parent bfc5eb3ee5
commit 9edd1bb0bb
2 changed files with 15 additions and 6 deletions

View File

@ -62,11 +62,11 @@ export class QueryTarget {
} }
selectWhile(range, predicate) { selectWhile(range, predicate) {
return this._selectWhile(range, predicate, "next"); return this._selectWhile(range, predicate, "next", false);
} }
selectWhileReverse(range, predicate) { selectWhileReverse(range, predicate) {
return this._selectWhile(range, predicate, "prev"); return this._selectWhile(range, predicate, "prev", false);
} }
async selectAll(range, direction) { async selectAll(range, direction) {
@ -153,15 +153,18 @@ export class QueryTarget {
_selectLimit(range, amount, direction) { _selectLimit(range, amount, direction) {
return this._selectWhile(range, (results) => { return this._selectWhile(range, (results) => {
return results.length === amount; return results.length === amount;
}, direction); }, direction, true);
} }
async _selectWhile(range, predicate, direction) { async _selectWhile(range, predicate, direction, includeFailingPredicateResult) {
const cursor = this._openCursor(range, direction); const cursor = this._openCursor(range, direction);
const results = []; const results = [];
await iterateCursor(cursor, (value) => { await iterateCursor(cursor, (value) => {
const passesPredicate = predicate(results, value);
if (passesPredicate || includeFailingPredicateResult) {
results.push(value); results.push(value);
return {done: predicate(results)}; }
return {done: passesPredicate};
}); });
return results; return results;
} }

View File

@ -34,4 +34,10 @@ export class RoomMemberStore {
return this._roomMembersStore.put(member); return this._roomMembersStore.put(member);
} }
getAll(roomId) {
const range = IDBKeyRange.lowerBound(encodeKey(roomId, ""));
return this._roomMembersStore.selectWhile(range, member => {
return member.roomId === roomId;
});
}
} }