Support deleting data in several stores for room id

This commit is contained in:
Bruno Windels 2021-05-12 15:38:11 +02:00
parent e233caf7ac
commit 5d139dff43
7 changed files with 61 additions and 2 deletions

View file

@ -113,10 +113,18 @@ export class QueryTarget {
return maxKey; return maxKey;
} }
async iterateValues(range, callback) {
const cursor = this._target.openCursor(range, "next");
await iterateCursor(cursor, (value, key, cur) => {
return {done: callback(value, key, cur)};
});
}
async iterateKeys(range, callback) { async iterateKeys(range, callback) {
const cursor = this._target.openKeyCursor(range, "next"); const cursor = this._target.openKeyCursor(range, "next");
await iterateCursor(cursor, (_, key) => { await iterateCursor(cursor, (_, key, cur) => {
return {done: callback(key)}; return {done: callback(key, cur)};
}); });
} }

View file

@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import {MIN_UNICODE, MAX_UNICODE} from "./common.js";
function encodeKey(roomId, sessionId, messageIndex) { function encodeKey(roomId, sessionId, messageIndex) {
return `${roomId}|${sessionId}|${messageIndex}`; return `${roomId}|${sessionId}|${messageIndex}`;
} }
@ -31,4 +33,12 @@ export class GroupSessionDecryptionStore {
decryption.key = encodeKey(roomId, sessionId, messageIndex); decryption.key = encodeKey(roomId, sessionId, messageIndex);
this._store.put(decryption); this._store.put(decryption);
} }
removeAllForRoom(roomId) {
const range = IDBKeyRange.bound(
encodeKey(roomId, MIN_UNICODE, MIN_UNICODE),
encodeKey(roomId, MAX_UNICODE, MAX_UNICODE)
);
this._store.delete(range);
}
} }

View file

@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import {MIN_UNICODE, MAX_UNICODE} from "./common.js";
function encodeKey(roomId, senderKey, sessionId) { function encodeKey(roomId, senderKey, sessionId) {
return `${roomId}|${senderKey}|${sessionId}`; return `${roomId}|${senderKey}|${sessionId}`;
} }
@ -37,4 +39,12 @@ export class InboundGroupSessionStore {
session.key = encodeKey(session.roomId, session.senderKey, session.sessionId); session.key = encodeKey(session.roomId, session.senderKey, session.sessionId);
this._store.put(session); this._store.put(session);
} }
removeAllForRoom(roomId) {
const range = IDBKeyRange.bound(
encodeKey(roomId, MIN_UNICODE, MIN_UNICODE),
encodeKey(roomId, MAX_UNICODE, MAX_UNICODE)
);
this._store.delete(range);
}
} }

View file

@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import {MIN_UNICODE, MAX_UNICODE} from "./common.js";
export function encodeScopeTypeKey(scope, type) { export function encodeScopeTypeKey(scope, type) {
return `${scope}|${type}`; return `${scope}|${type}`;
@ -52,4 +53,16 @@ export class OperationStore {
remove(id) { remove(id) {
this._store.delete(id); this._store.delete(id);
} }
async removeAllForScope(scope) {
const range = IDBKeyRange.bound(
encodeScopeTypeKey(scope, MIN_UNICODE),
encodeScopeTypeKey(scope, MAX_UNICODE)
);
const index = this._store.index("byScopeAndType");
await index.iterateValues(range, (_, __, cur) => {
cur.delete();
return true;
});
}
} }

View file

@ -68,4 +68,11 @@ export class PendingEventStore {
getAll() { getAll() {
return this._eventStore.selectAll(); return this._eventStore.selectAll();
} }
removeAllForRoom(roomId) {
const minKey = encodeKey(roomId, KeyLimits.minStorageKey);
const maxKey = encodeKey(roomId, KeyLimits.maxStorageKey);
const range = IDBKeyRange.bound(minKey, maxKey);
this._eventStore.delete(range);
}
} }

View file

@ -257,4 +257,11 @@ export class TimelineEventStore {
getByEventId(roomId, eventId) { getByEventId(roomId, eventId) {
return this._timelineStore.index("byEventId").get(encodeEventIdKey(roomId, eventId)); return this._timelineStore.index("byEventId").get(encodeEventIdKey(roomId, eventId));
} }
removeAllForRoom(roomId) {
const minKey = encodeKey(roomId, KeyLimits.minStorageKey, KeyLimits.minStorageKey);
const maxKey = encodeKey(roomId, KeyLimits.maxStorageKey, KeyLimits.maxStorageKey);
const range = IDBKeyRange.bound(minKey, maxKey);
this._timelineStore.delete(range);
}
} }

View file

@ -72,4 +72,8 @@ export class TimelineFragmentStore {
get(roomId, fragmentId) { get(roomId, fragmentId) {
return this._store.get(encodeKey(roomId, fragmentId)); return this._store.get(encodeKey(roomId, fragmentId));
} }
removeAllForRoom(roomId) {
this._store.delete(this._allRange(roomId));
}
} }