Bug 707946 - Improve performances of hasChildren for tag queries.

r=dietrich sr=gavin
This commit is contained in:
Marco Bonardo 2011-12-07 21:56:26 +01:00
parent 2a5ab1a723
commit bdcf6b49e6
4 changed files with 31 additions and 19 deletions

View File

@ -110,6 +110,9 @@
#define NS_LIVEMARKSERVICE_CONTRACTID \
"@mozilla.org/browser/livemark-service;2"
#define NS_TAGGINGSERVICE_CONTRACTID \
"@mozilla.org/browser/tagging-service;1"
#define NS_FAVICONSERVICE_CONTRACTID \
"@mozilla.org/browser/favicon-service;1"

View File

@ -41,7 +41,7 @@
interface nsIURI;
interface nsIVariant;
[scriptable, uuid(e39cea60-7e6d-4c8b-80a3-997af1c2cbcb)]
[scriptable, uuid(f816b4df-f733-4dbd-964d-8bfc92a475b2)]
interface nsITaggingService : nsISupports
{
/**
@ -95,6 +95,13 @@ interface nsITaggingService : nsISupports
* Retrieves all tags used to tag URIs in the data-base (sorted by name).
*/
readonly attribute nsIVariant allTags;
/**
* Whether any tags exist.
*
* @note This is faster than allTags.length, since doesn't need to sort tags.
*/
readonly attribute boolean hasTags;
};
%{C++

View File

@ -2247,31 +2247,28 @@ nsNavHistoryQueryResultNode::OpenContainer()
NS_IMETHODIMP
nsNavHistoryQueryResultNode::GetHasChildren(bool* aHasChildren)
{
*aHasChildren = false;
if (!CanExpand()) {
*aHasChildren = false;
return NS_OK;
}
PRUint16 resultType = mOptions->ResultType();
// Tags are always populated, otherwise they are removed.
if (resultType == nsINavHistoryQueryOptions::RESULTS_AS_TAG_CONTENTS) {
*aHasChildren = true;
return NS_OK;
}
// For tag containers query we must check if we have any tag
if (resultType == nsINavHistoryQueryOptions::RESULTS_AS_TAG_QUERY) {
nsRefPtr<Database> DB = Database::GetDatabase();
NS_ENSURE_STATE(DB);
nsCOMPtr<mozIStorageStatement> stmt = DB->GetStatement(
"SELECT id FROM moz_bookmarks WHERE parent = :tags_folder LIMIT 1"
);
NS_ENSURE_STATE(stmt);
mozStorageStatementScoper scoper(stmt);
nsNavHistory* history = nsNavHistory::GetHistoryService();
NS_ENSURE_STATE(history);
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("tags_folder"),
history->GetTagsFolder());
NS_ENSURE_SUCCESS(rv, rv);
rv = stmt->ExecuteStep(aHasChildren);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsITaggingService> tagging =
do_GetService(NS_TAGGINGSERVICE_CONTRACTID);
if (tagging) {
bool hasTags;
*aHasChildren = NS_SUCCEEDED(tagging->GetHasTags(&hasTags)) && hasTags;
}
return NS_OK;
}

View File

@ -350,6 +350,11 @@ TaggingService.prototype = {
return allTags;
},
// nsITaggingService
get hasTags() {
return this._tagFolders.length > 0;
},
// nsIObserver
observe: function TS_observe(aSubject, aTopic, aData) {
if (aTopic == TOPIC_SHUTDOWN) {