allow passing txn to loadMembers so we can do it as part of sync txn

to rewrite useridentities upon receiving new history visibility
This commit is contained in:
Bruno Windels 2022-07-26 16:53:02 +02:00
parent a23df8a545
commit 4c17612b05
3 changed files with 17 additions and 11 deletions

View file

@ -116,12 +116,13 @@ export class DeviceTracker {
if (room.isTrackingMembers || !room.isEncrypted) {
return;
}
const memberList = await room.loadMemberList(log);
const txn = await this._storage.readWriteTxn([
this._storage.storeNames.roomSummary,
this._storage.storeNames.userIdentities,
]);
let memberList;
try {
const txn = await this._storage.readWriteTxn([
this._storage.storeNames.roomSummary,
this._storage.storeNames.userIdentities,
]);
memberList = await room.loadMemberList(txn, log);
let isTrackingChanges;
try {
isTrackingChanges = room.writeIsTrackingMembers(true, txn);
@ -139,7 +140,7 @@ export class DeviceTracker {
await txn.complete();
room.applyIsTrackingMembersChanges(isTrackingChanges);
} finally {
memberList.release();
memberList?.release();
}
}

View file

@ -243,7 +243,7 @@ export class BaseRoom extends EventEmitter {
/** @public */
async loadMemberList(log = null) {
async loadMemberList(txn = undefined, log = null) {
if (this._memberList) {
// TODO: also await fetchOrLoadMembers promise here
this._memberList.retain();
@ -254,6 +254,9 @@ export class BaseRoom extends EventEmitter {
roomId: this._roomId,
hsApi: this._hsApi,
storage: this._storage,
// pass in a transaction if we know we won't need to fetch (which would abort the transaction)
// and we want to make this operation part of the larger transaction
txn,
syncToken: this._getSyncToken(),
// to handle race between /members and /sync
setChangedMembersMap: map => this._changedMembersDuringSync = map,

View file

@ -17,10 +17,12 @@ limitations under the License.
import {RoomMember} from "./RoomMember.js";
async function loadMembers({roomId, storage}) {
const txn = await storage.readTxn([
storage.storeNames.roomMembers,
]);
async function loadMembers({roomId, storage, txn}) {
if (!txn) {
txn = await storage.readTxn([
storage.storeNames.roomMembers,
]);
}
const memberDatas = await txn.roomMembers.getAll(roomId);
return memberDatas.map(d => new RoomMember(d));
}