Don't clean empty data.

This commit is contained in:
Zixaphir 2014-03-26 11:16:05 -07:00
parent 04f5f5a5fb
commit f6ea1ed52c
4 changed files with 24 additions and 8 deletions

View File

@ -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

View File

@ -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
});

View File

@ -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
});

View File

@ -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