You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Merge pull request #724 from matrix-org/bwindels/fastermemberinsert
Reduce amount of promises created when inserting members
This commit is contained in:
@@ -265,42 +265,28 @@ LocalIndexedDBStoreBackend.prototype = {
|
|||||||
* marked as fetched, and getOutOfBandMembers will return an empty array instead of null
|
* marked as fetched, and getOutOfBandMembers will return an empty array instead of null
|
||||||
* @param {string} roomId
|
* @param {string} roomId
|
||||||
* @param {event[]} membershipEvents the membership events to store
|
* @param {event[]} membershipEvents the membership events to store
|
||||||
* @returns {Promise} when all members have been stored
|
|
||||||
*/
|
*/
|
||||||
setOutOfBandMembers: function(roomId, membershipEvents) {
|
setOutOfBandMembers: async function(roomId, membershipEvents) {
|
||||||
console.log(`LL: backend about to store ${membershipEvents.length}` +
|
console.log(`LL: backend about to store ${membershipEvents.length}` +
|
||||||
` members for ${roomId}`);
|
` members for ${roomId}`);
|
||||||
function ignoreResult() {}
|
const tx = this.db.transaction(["oob_membership_events"], "readwrite");
|
||||||
// run everything in a promise so anything that throws will reject
|
const store = tx.objectStore("oob_membership_events");
|
||||||
return new Promise((resolve) =>{
|
membershipEvents.forEach((e) => {
|
||||||
const tx = this.db.transaction(["oob_membership_events"], "readwrite");
|
store.put(e);
|
||||||
const store = tx.objectStore("oob_membership_events");
|
|
||||||
const eventPuts = membershipEvents.map((e) => {
|
|
||||||
const putPromise = reqAsEventPromise(store.put(e));
|
|
||||||
// ignoring the result makes sure we discard the IDB success event
|
|
||||||
// ASAP, and not create a potentially big array containing them
|
|
||||||
// unneccesarily later on by calling Promise.all.
|
|
||||||
return putPromise.then(ignoreResult);
|
|
||||||
});
|
|
||||||
// aside from all the events, we also write a marker object to the store
|
|
||||||
// to mark the fact that OOB members have been written for this room.
|
|
||||||
// It's possible that 0 members need to be written as all where previously know
|
|
||||||
// but we still need to know whether to return null or [] from getOutOfBandMembers
|
|
||||||
// where null means out of band members haven't been stored yet for this room
|
|
||||||
const markerObject = {
|
|
||||||
room_id: roomId,
|
|
||||||
oob_written: true,
|
|
||||||
state_key: 0,
|
|
||||||
};
|
|
||||||
const markerPut = reqAsEventPromise(store.put(markerObject));
|
|
||||||
const allPuts = eventPuts.concat(markerPut);
|
|
||||||
// ignore the empty array Promise.all creates
|
|
||||||
// as this method should just resolve
|
|
||||||
// to undefined on success
|
|
||||||
resolve(Promise.all(allPuts).then(ignoreResult));
|
|
||||||
}).then(() => {
|
|
||||||
console.log(`LL: backend done storing for ${roomId}!`);
|
|
||||||
});
|
});
|
||||||
|
// aside from all the events, we also write a marker object to the store
|
||||||
|
// to mark the fact that OOB members have been written for this room.
|
||||||
|
// It's possible that 0 members need to be written as all where previously know
|
||||||
|
// but we still need to know whether to return null or [] from getOutOfBandMembers
|
||||||
|
// where null means out of band members haven't been stored yet for this room
|
||||||
|
const markerObject = {
|
||||||
|
room_id: roomId,
|
||||||
|
oob_written: true,
|
||||||
|
state_key: 0,
|
||||||
|
};
|
||||||
|
store.put(markerObject);
|
||||||
|
await txnAsPromise(tx);
|
||||||
|
console.log(`LL: backend done storing for ${roomId}!`);
|
||||||
},
|
},
|
||||||
|
|
||||||
clearOutOfBandMembers: async function(roomId) {
|
clearOutOfBandMembers: async function(roomId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user