diff --git a/lib/ActivityStreams.js b/lib/ActivityStreams.js index 96f9a2aef..558ef69cc 100644 --- a/lib/ActivityStreams.js +++ b/lib/ActivityStreams.js @@ -241,6 +241,8 @@ ActivityStreams.prototype = { getRecentBookmarks: cache.memoize("getRecentBookmarks", PlacesProvider.links.getRecentBookmarks.bind(linksObj)), getRecentLinks: cache.memoize("getRecentLinks", PlacesProvider.links.getRecentLinks.bind(linksObj)), getFrecentLinks: cache.memoize("getFrecentLinks", PlacesProvider.links.getFrecentLinks.bind(linksObj)), + getHistorySize: cache.memoize("getHistorySize", PlacesProvider.links.getHistorySize.bind(linksObj)), + getBookmarksSize: cache.memoize("getBookmarksSize", PlacesProvider.links.getBookmarksSize.bind(linksObj)), }; }, @@ -256,8 +258,10 @@ ActivityStreams.prototype = { this._memoized.getRecentBookmarks(), this._memoized.getRecentLinks(), this._memoized.getFrecentLinks(), + this._memoized.getHistorySize(), + this._memoized.getBookmarksSize(), ]); - Services.obs.notifyObservers(null, "activity-streams-places-cache-complete", null); + Services.obs.notifyObservers(null, "activity-streams-places-cache-complete", this._memoized); } }), @@ -269,7 +273,9 @@ ActivityStreams.prototype = { "getTopFrecentSites", "getRecentBookmarks", "getRecentLinks", - "getFrecentLinks" + "getFrecentLinks", + "getHistorySize", + "getBookmarksSize", ]); }, diff --git a/lib/PlacesProvider.js b/lib/PlacesProvider.js index 63f40bbeb..35769c5b3 100644 --- a/lib/PlacesProvider.js +++ b/lib/PlacesProvider.js @@ -449,6 +449,34 @@ Links.prototype = { }); }, + /** + * Gets History size + * + * @returns {Promise} Returns a promise with the count of moz_places records + */ + getHistorySize: Task.async(function*() { + let sqlQuery = `SELECT count(1) as count + FROM moz_places + WHERE hidden = 0 AND last_visit_date NOT NULL`; + + let result = yield this.executePlacesQuery(sqlQuery); + return result[0][0]; + }), + + /** + * Gets Bookmarks count + * + * @returns {Promise} Returns a promise with the count of bookmarks + */ + getBookmarksSize: Task.async(function*() { + let sqlQuery = `SELECT count(1) as count + FROM moz_bookmarks + WHERE type = :type`; + + let result = yield this.executePlacesQuery(sqlQuery, {params: {type: Bookmarks.TYPE_BOOKMARK}}); + return result[0][0]; + }), + /** * Executes arbitrary query against places database * diff --git a/test/test-PlacesProvider.js b/test/test-PlacesProvider.js index d3bd7bda0..f5686eb6d 100644 --- a/test/test-PlacesProvider.js +++ b/test/test-PlacesProvider.js @@ -277,6 +277,8 @@ exports.test_Links_getRecentBookmarks_Order = function*(assert) { let links = yield provider.getRecentBookmarks(); assert.equal(links.length, 0, "empty bookmarks yields empty links"); + let bookmarksSize = yield provider.getBookmarksSize(); + assert.equal(bookmarksSize, 0, "empty bookmarks yields 0 size"); let base64URL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAA" + "AAAA6fptVAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg=="; @@ -359,6 +361,9 @@ exports.test_Links_getRecentBookmarks_Order = function*(assert) { assert.ok(links[i].lastModified < yesterday, "bookmark lastModifed date is before yesterday"); } + bookmarksSize = yield provider.getBookmarksSize(); + assert.equal(bookmarksSize, createdBookmarks.length, "expected count of bookmarks"); + // cleanup yield Bookmarks.remove({guid: folder.guid}); provider.uninit(); @@ -586,6 +591,20 @@ exports.test_Links__faviconBytesToDataURI = function(assert) { } }; +exports.test_Links_getHistorySize = function*(assert) { + let provider = PlacesProvider.links; + + let size = yield provider.getHistorySize(); + assert.equal(size, 0, "empty history has 0 size"); + + // add a visit + let testURI = NetUtil.newURI("http://mozilla.com"); + yield PlacesTestUtils.addVisits(testURI); + + size = yield provider.getHistorySize(); + assert.equal(size, 1, "expected history size"); +}; + before(exports, function*() { let faviconExpiredPromise = new Promise(resolve => { systemEvents.once("places-favicons-expired", resolve);