Support deleting data in several stores for room id
This commit is contained in:
parent
e233caf7ac
commit
5d139dff43
7 changed files with 61 additions and 2 deletions
|
@ -113,10 +113,18 @@ export class QueryTarget {
|
|||
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) {
|
||||
const cursor = this._target.openKeyCursor(range, "next");
|
||||
await iterateCursor(cursor, (_, key) => {
|
||||
return {done: callback(key)};
|
||||
await iterateCursor(cursor, (_, key, cur) => {
|
||||
return {done: callback(key, cur)};
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import {MIN_UNICODE, MAX_UNICODE} from "./common.js";
|
||||
|
||||
function encodeKey(roomId, sessionId, messageIndex) {
|
||||
return `${roomId}|${sessionId}|${messageIndex}`;
|
||||
}
|
||||
|
@ -31,4 +33,12 @@ export class GroupSessionDecryptionStore {
|
|||
decryption.key = encodeKey(roomId, sessionId, messageIndex);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import {MIN_UNICODE, MAX_UNICODE} from "./common.js";
|
||||
|
||||
function encodeKey(roomId, senderKey, sessionId) {
|
||||
return `${roomId}|${senderKey}|${sessionId}`;
|
||||
}
|
||||
|
@ -37,4 +39,12 @@ export class InboundGroupSessionStore {
|
|||
session.key = encodeKey(session.roomId, session.senderKey, session.sessionId);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
limitations under the License.
|
||||
*/
|
||||
import {MIN_UNICODE, MAX_UNICODE} from "./common.js";
|
||||
|
||||
export function encodeScopeTypeKey(scope, type) {
|
||||
return `${scope}|${type}`;
|
||||
|
@ -52,4 +53,16 @@ export class OperationStore {
|
|||
remove(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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,4 +68,11 @@ export class PendingEventStore {
|
|||
getAll() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -257,4 +257,11 @@ export class TimelineEventStore {
|
|||
getByEventId(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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,4 +72,8 @@ export class TimelineFragmentStore {
|
|||
get(roomId, fragmentId) {
|
||||
return this._store.get(encodeKey(roomId, fragmentId));
|
||||
}
|
||||
|
||||
removeAllForRoom(roomId) {
|
||||
this._store.delete(this._allRange(roomId));
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue