mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
reduce megolm sync cache size to 1 session
as this is kept around for every e2ee room, and we only have limited olm memory
This commit is contained in:
parent
16b3b7e282
commit
07701117cd
@ -41,7 +41,7 @@ export class RoomEncryption {
|
|||||||
this._encryptionParams = encryptionParams;
|
this._encryptionParams = encryptionParams;
|
||||||
|
|
||||||
this._megolmBackfillCache = this._megolmDecryption.createSessionCache();
|
this._megolmBackfillCache = this._megolmDecryption.createSessionCache();
|
||||||
this._megolmSyncCache = this._megolmDecryption.createSessionCache();
|
this._megolmSyncCache = this._megolmDecryption.createSessionCache(1);
|
||||||
// session => event ids of messages we tried to decrypt and the session was missing
|
// session => event ids of messages we tried to decrypt and the session was missing
|
||||||
this._missingSessions = new SessionToEventIdsMap();
|
this._missingSessions = new SessionToEventIdsMap();
|
||||||
// sessions that may or may not be missing, but that while
|
// sessions that may or may not be missing, but that while
|
||||||
|
@ -41,8 +41,8 @@ export class Decryption {
|
|||||||
this._olmWorker = olmWorker;
|
this._olmWorker = olmWorker;
|
||||||
}
|
}
|
||||||
|
|
||||||
createSessionCache(fallback) {
|
createSessionCache(size) {
|
||||||
return new SessionCache(fallback);
|
return new SessionCache(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,13 +14,14 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const CACHE_MAX_SIZE = 10;
|
const DEFAULT_CACHE_SIZE = 10;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache of unpickled inbound megolm session.
|
* Cache of unpickled inbound megolm session.
|
||||||
*/
|
*/
|
||||||
export class SessionCache {
|
export class SessionCache {
|
||||||
constructor() {
|
constructor(size) {
|
||||||
|
this._size = typeof size === "number" ? size : DEFAULT_CACHE_SIZE;
|
||||||
this._sessions = [];
|
this._sessions = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,12 +52,12 @@ export class SessionCache {
|
|||||||
sessionInfo.retain();
|
sessionInfo.retain();
|
||||||
// add new at top
|
// add new at top
|
||||||
this._sessions.unshift(sessionInfo);
|
this._sessions.unshift(sessionInfo);
|
||||||
if (this._sessions.length > CACHE_MAX_SIZE) {
|
if (this._sessions.length > this._size) {
|
||||||
// free sessions we're about to remove
|
// free sessions we're about to remove
|
||||||
for (let i = CACHE_MAX_SIZE; i < this._sessions.length; i += 1) {
|
for (let i = this._size; i < this._sessions.length; i += 1) {
|
||||||
this._sessions[i].release();
|
this._sessions[i].release();
|
||||||
}
|
}
|
||||||
this._sessions = this._sessions.slice(0, CACHE_MAX_SIZE);
|
this._sessions = this._sessions.slice(0, this._size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user