Skip to content

Commit

Permalink
Force existing DB_SUSPENDED_TABINFO items to generate new ids
Browse files Browse the repository at this point in the history
Force existing DB_SUSPENDED_TABINFO items to generate new ids so that
the trimDbItems function will always trim the oldest items. Also
increase the number of DB_PREVIEWS items to match that of
DB_SUSPENDED_TABINFO items.
  • Loading branch information
deanoemcke committed Aug 18, 2017
1 parent 8447f48 commit b4cd24c
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions src/js/gsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,12 @@

}).then(function (results) {
if (results.length > 0) {
server.update(self.DB_PREVIEWS , {id: results[0].id, url: tabUrl, img: previewUrl, pos: position});

return server.remove(self.DB_PREVIEWS, results[0].id);
} else {
server.add(self.DB_PREVIEWS , {url: tabUrl, img: previewUrl, pos: position});
return Promise.resolve();
}
}).then(function() {
server.add(self.DB_PREVIEWS, {url: tabUrl, img: previewUrl, pos: position});
});
},

Expand All @@ -342,20 +343,16 @@
server = s;
return server.query(self.DB_SUSPENDED_TABINFO).filter('url', tabProperties.url).execute();

}).then(function(result) {
if (result.length > 0) {
result = result[0];
//copy across id
tabProperties.id = result.id;
//then update based on that id
server.update(self.DB_SUSPENDED_TABINFO, tabProperties).then(function() {
if (typeof(callback) === "function") callback();
});
}).then(function(results) {
if (results.length > 0) {
return server.remove(self.DB_SUSPENDED_TABINFO, results[0].id);
} else {
server.add(self.DB_SUSPENDED_TABINFO, tabProperties).then(function() {
if (typeof(callback) === "function") callback();
});
return Promise.resolve();
}
}).then(function() {
server.add(self.DB_SUSPENDED_TABINFO, tabProperties).then(function() {
if (typeof(callback) === "function") callback();
});
});
},

Expand Down Expand Up @@ -567,7 +564,6 @@
var self = this,
server,
maxTabItems = 1000,
maxPreviewItems = 200,
maxHistories = 5,
itemsToRemove,
i;
Expand Down Expand Up @@ -598,9 +594,9 @@
//trim imagePreviews
}).then(function (results) {

//if there are more than maxPreviewItems items, then remove the oldest ones
if (results.length > maxPreviewItems) {
itemsToRemove = results.length - maxPreviewItems;
//if there are more than maxTabItems items, then remove the oldest ones
if (results.length > maxTabItems) {
itemsToRemove = results.length - maxTabItems;
for (i = 0; i < itemsToRemove; i++) {
server.remove(self.DB_PREVIEWS, results[i]);
}
Expand Down

0 comments on commit b4cd24c

Please sign in to comment.