From 1608618560be986f38603605256852029fb11066 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 26 Aug 2016 14:00:28 +0200 Subject: [PATCH] Improved autosave cleanup, fixes #2095 --- .../WoltLabSuite/Core/Ui/Redactor/Autosave.js | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Autosave.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Autosave.js index 74fc977ebe..d964565cef 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Autosave.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Autosave.js @@ -160,9 +160,9 @@ define(['Dom/Traverse'], function(DomTraverse) { * @protected */ _cleanup: function () { - var oneWeekAgo = Date.now() - (7 * 24 * 3600 * 1000); - var key, value; - for (var i = 0, length = window.localStorage.length; i < length; i++) { + var oneWeekAgo = Date.now() - (7 * 24 * 3600 * 1000), removeKeys = []; + var i, key, length, value; + for (i = 0, length = window.localStorage.length; i < length; i++) { key = window.localStorage.key(i); // check if key matches our prefix @@ -185,12 +185,16 @@ define(['Dom/Traverse'], function(DomTraverse) { } if (!value || value.timestamp < oneWeekAgo) { - try { - window.localStorage.removeItem(key); - } - catch (e) { - window.console.warn("Unable to remove from local storage: " + e.message); - } + removeKeys.push(key); + } + } + + for (i = 0, length = removeKeys.length; i < length; i++) { + try { + window.localStorage.removeItem(removeKeys[i]); + } + catch (e) { + window.console.warn("Unable to remove from local storage: " + e.message); } } } -- 2.20.1