feat(reporting): History/Bookmark size API and caching
This commit is contained in:
Родитель
52ab9d4c06
Коммит
a55da33a5f
|
@ -241,6 +241,8 @@ ActivityStreams.prototype = {
|
||||||
getRecentBookmarks: cache.memoize("getRecentBookmarks", PlacesProvider.links.getRecentBookmarks.bind(linksObj)),
|
getRecentBookmarks: cache.memoize("getRecentBookmarks", PlacesProvider.links.getRecentBookmarks.bind(linksObj)),
|
||||||
getRecentLinks: cache.memoize("getRecentLinks", PlacesProvider.links.getRecentLinks.bind(linksObj)),
|
getRecentLinks: cache.memoize("getRecentLinks", PlacesProvider.links.getRecentLinks.bind(linksObj)),
|
||||||
getFrecentLinks: cache.memoize("getFrecentLinks", PlacesProvider.links.getFrecentLinks.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.getRecentBookmarks(),
|
||||||
this._memoized.getRecentLinks(),
|
this._memoized.getRecentLinks(),
|
||||||
this._memoized.getFrecentLinks(),
|
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",
|
"getTopFrecentSites",
|
||||||
"getRecentBookmarks",
|
"getRecentBookmarks",
|
||||||
"getRecentLinks",
|
"getRecentLinks",
|
||||||
"getFrecentLinks"
|
"getFrecentLinks",
|
||||||
|
"getHistorySize",
|
||||||
|
"getBookmarksSize",
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -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
|
* Executes arbitrary query against places database
|
||||||
*
|
*
|
||||||
|
|
|
@ -277,6 +277,8 @@ exports.test_Links_getRecentBookmarks_Order = function*(assert) {
|
||||||
|
|
||||||
let links = yield provider.getRecentBookmarks();
|
let links = yield provider.getRecentBookmarks();
|
||||||
assert.equal(links.length, 0, "empty bookmarks yields empty links");
|
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" +
|
let base64URL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAA" +
|
||||||
"AAAA6fptVAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg==";
|
"AAAA6fptVAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg==";
|
||||||
|
@ -359,6 +361,9 @@ exports.test_Links_getRecentBookmarks_Order = function*(assert) {
|
||||||
assert.ok(links[i].lastModified < yesterday, "bookmark lastModifed date is before yesterday");
|
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
|
// cleanup
|
||||||
yield Bookmarks.remove({guid: folder.guid});
|
yield Bookmarks.remove({guid: folder.guid});
|
||||||
provider.uninit();
|
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*() {
|
before(exports, function*() {
|
||||||
let faviconExpiredPromise = new Promise(resolve => {
|
let faviconExpiredPromise = new Promise(resolve => {
|
||||||
systemEvents.once("places-favicons-expired", resolve);
|
systemEvents.once("places-favicons-expired", resolve);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче