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

View file

@ -243,7 +243,7 @@ export class BaseRoom extends EventEmitter {
/** @public */ /** @public */
async loadMemberList(log = null) { async loadMemberList(txn = undefined, log = null) {
if (this._memberList) { if (this._memberList) {
// TODO: also await fetchOrLoadMembers promise here // TODO: also await fetchOrLoadMembers promise here
this._memberList.retain(); this._memberList.retain();
@ -254,6 +254,9 @@ export class BaseRoom extends EventEmitter {
roomId: this._roomId, roomId: this._roomId,
hsApi: this._hsApi, hsApi: this._hsApi,
storage: this._storage, 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(), syncToken: this._getSyncToken(),
// to handle race between /members and /sync // to handle race between /members and /sync
setChangedMembersMap: map => this._changedMembersDuringSync = map, setChangedMembersMap: map => this._changedMembersDuringSync = map,

View file

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