From f6ea1ed52c8e584bce8217b1f25206dc270416b2 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Wed, 26 Mar 2014 11:16:05 -0700 Subject: [PATCH] Don't clean empty data. --- LICENSE | 2 +- builds/4chan-X.user.js | 11 ++++++++--- builds/crx/script.js | 11 ++++++++--- src/General/lib/databoard.class | 8 +++++++- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/LICENSE b/LICENSE index 46d565a33..9017b2c6d 100755 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* -* 4chan X - Version 1.4.1 - 2014-03-24 +* 4chan X - Version 1.4.1 - 2014-03-26 * * Licensed under the MIT license. * https://github.com/Spittie/4chan-x/blob/master/LICENSE diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 844958879..7fdded0ab 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -24,7 +24,7 @@ // ==/UserScript== /* -* 4chan X - Version 1.4.1 - 2014-03-24 +* 4chan X - Version 1.4.1 - 2014-03-26 * * Licensed under the MIT license. * https://github.com/Spittie/4chan-x/blob/master/LICENSE @@ -1620,12 +1620,17 @@ }; DataBoard.prototype.clean = function() { - var boardID, now; + var boardID, keys, now, _i, _len; now = Date.now(); if ((this.data.lastChecked || 0) > now - 2 * $.HOUR) { return; } - for (boardID in this.data.boards) { + keys = Object.keys(this.data.boards); + if (!keys.length) { + return; + } + for (_i = 0, _len = keys.length; _i < _len; _i++) { + boardID = keys[_i]; this.deleteIfEmpty({ boardID: boardID }); diff --git a/builds/crx/script.js b/builds/crx/script.js index 9fbd5a3e5..9ea19e956 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript /* -* 4chan X - Version 1.4.1 - 2014-03-24 +* 4chan X - Version 1.4.1 - 2014-03-26 * * Licensed under the MIT license. * https://github.com/Spittie/4chan-x/blob/master/LICENSE @@ -1677,12 +1677,17 @@ }; DataBoard.prototype.clean = function() { - var boardID, now; + var boardID, keys, now, _i, _len; now = Date.now(); if ((this.data.lastChecked || 0) > now - 2 * $.HOUR) { return; } - for (boardID in this.data.boards) { + keys = Object.keys(this.data.boards); + if (!keys.length) { + return; + } + for (_i = 0, _len = keys.length; _i < _len; _i++) { + boardID = keys[_i]; this.deleteIfEmpty({ boardID: boardID }); diff --git a/src/General/lib/databoard.class b/src/General/lib/databoard.class index 5af46b36d..a93e90e1a 100755 --- a/src/General/lib/databoard.class +++ b/src/General/lib/databoard.class @@ -64,7 +64,13 @@ class DataBoard now = Date.now() return if (@data.lastChecked or 0) > now - 2 * $.HOUR - for boardID of @data.boards + # Don't even bother writing unless we have data to write + keys = Object.keys @data.boards + return unless keys.length + + # Since we generated the keys anyways, use them to avoid the slow ``Object::hasOwnProperty`` method + # Not that ``Object.keys`` is fast + for boardID in keys @deleteIfEmpty {boardID} @ajaxClean boardID if boardID of @data.boards