From e656a67c16b4e2f4c63878fbe4bad25c45024e76 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 11:05:39 +0100 Subject: [PATCH 1/7] Fix channel cache --- www/common/outer/cache-store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/common/outer/cache-store.js b/www/common/outer/cache-store.js index 067d2dda7..73dbb1a3e 100644 --- a/www/common/outer/cache-store.js +++ b/www/common/outer/cache-store.js @@ -94,7 +94,7 @@ define([ S.storeCache = function (id, validateKey, val, cb) { cb = Util.once(Util.mkAsync(cb || function () {})); - onReady.reg(function (allowed) { + onReady.reg(function () { if (!allowed) { return void cb('NOCACHE'); } if (!Array.isArray(val) || !validateKey) { return void cb('EINVAL'); } checkCheckpoints(val); From e3102d2746cd6ade72334029e4703924c3be7cc6 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 11:52:24 +0100 Subject: [PATCH 2/7] Throttle channel cache --- www/common/outer/cache-store.js | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/www/common/outer/cache-store.js b/www/common/outer/cache-store.js index 73dbb1a3e..ad9f1e04f 100644 --- a/www/common/outer/cache-store.js +++ b/www/common/outer/cache-store.js @@ -91,20 +91,29 @@ define([ array.splice(0, firstCpIdx); }; - S.storeCache = function (id, validateKey, val, cb) { - cb = Util.once(Util.mkAsync(cb || function () {})); + var t = {}; + S.storeCache = function (id, validateKey, val, onError) { + onError = Util.once(Util.mkAsync(onError || function () {})); onReady.reg(function () { - if (!allowed) { return void cb('NOCACHE'); } - if (!Array.isArray(val) || !validateKey) { return void cb('EINVAL'); } - checkCheckpoints(val); - cache.setItem(id, { - k: validateKey, - c: val, - t: (+new Date()) // 't' represent the "lastAccess" of this cache (get or set) - }, function (err) { - cb(err); - }); + + // Make a throttle or use the existing one to avoid calling + // storeCache with the same array multiple times + t[id] = t[id] || Util.throttle(function (validateKey, val, onError) { + if (!allowed) { return void onError('NOCACHE'); } + if (!Array.isArray(val) || !validateKey) { return void onError('EINVAL'); } + checkCheckpoints(val); + cache.setItem(id, { + k: validateKey, + c: val, + t: (+new Date()) // 't' represent the "lastAccess" of this cache (get or set) + }, function (err) { + if (err) { onError(err); } + }); + + }, 50); + t[id](validateKey, val, onError); + }); }; From ab4739005be4b5a17e9316b7aecb7f3250361bd8 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 11:57:46 +0100 Subject: [PATCH 3/7] Fix X icon in the share modal --- www/common/inner/share.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/common/inner/share.js b/www/common/inner/share.js index f3ca53f75..2be698d74 100644 --- a/www/common/inner/share.js +++ b/www/common/inner/share.js @@ -345,7 +345,7 @@ define([ localStore.get('hide-alert-shareLinkWarning', function (val) { if (val === '1') { return; } - $(shareLinkWarning).show(); + $(shareLinkWarning).css('display', 'flex'); $(dismissButton).on('click', function () { localStore.put('hide-alert-shareLinkWarning', '1'); From b3f91dd9a28240d61ee7c209a133c064a5c58fb4 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 12:02:48 +0100 Subject: [PATCH 4/7] Fix button margin in admin panel --- www/admin/app-admin.less | 3 +++ 1 file changed, 3 insertions(+) diff --git a/www/admin/app-admin.less b/www/admin/app-admin.less index 651e9dddd..8fff2e528 100644 --- a/www/admin/app-admin.less +++ b/www/admin/app-admin.less @@ -31,6 +31,9 @@ margin-top: 5px; } } + .cp-admin-setlimit-form + button { + margin-top: 5px !important; + } .cp-admin-getlimits { code { cursor: pointer; From 51ebdf4ed2433822c55f82fab9b1f4f044e15b25 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 12:06:18 +0100 Subject: [PATCH 5/7] Clear throttled functions in cache --- www/common/outer/async-store.js | 3 +++ www/common/outer/cache-store.js | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index afb799990..da7abf9d0 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -2277,6 +2277,9 @@ define([ try { store.onlyoffice.leavePad(chanId); } catch (e) { console.error(e); } + try { + Cache.leaveChannel(chanId); + } catch (e) { console.error(e); } if (!Store.channels[chanId]) { return; } diff --git a/www/common/outer/cache-store.js b/www/common/outer/cache-store.js index ad9f1e04f..4b21e22fe 100644 --- a/www/common/outer/cache-store.js +++ b/www/common/outer/cache-store.js @@ -117,6 +117,13 @@ define([ }); }; + S.leaveChannel = function (id) { + if (t[id] && typeof(t[id].clear) === "function") { + t[id].clear(); + } + delete t[id]; + }; + S.clearChannel = function (id, cb) { cb = Util.once(Util.mkAsync(cb || function () {})); From 453b207bcc02f72bc7cf3dba8ee38ceebe11df7f Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 12:09:19 +0100 Subject: [PATCH 6/7] Remove the throttled function from memory only --- www/common/outer/cache-store.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/www/common/outer/cache-store.js b/www/common/outer/cache-store.js index 4b21e22fe..7a0a50209 100644 --- a/www/common/outer/cache-store.js +++ b/www/common/outer/cache-store.js @@ -118,9 +118,6 @@ define([ }; S.leaveChannel = function (id) { - if (t[id] && typeof(t[id].clear) === "function") { - t[id].clear(); - } delete t[id]; }; From dfc2d6ce0ddfedd4af3de0f441e59dec365bd8ed Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 13:31:39 +0100 Subject: [PATCH 7/7] Remove deleted pad from cache --- www/common/outer/async-store.js | 1 + 1 file changed, 1 insertion(+) diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index da7abf9d0..90318dba5 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -331,6 +331,7 @@ define([ if (!s.rpc) { return void cb({error: 'RPC_NOT_READY'}); } s.rpc.removeOwnedChannel(channel, function (err) { + if (!err) { Cache.clearChannel(channel); } cb({error:err}); }); };