From 5d32fe1854731f0fed4de1ce864ea2c90212814a Mon Sep 17 00:00:00 2001 From: "dietrich@mozilla.com" Date: Tue, 9 Oct 2007 12:14:48 -0700 Subject: [PATCH] Bug 398896 New history search hang since 6 Sep 2007 (r=sspitzer) --- .../components/places/src/nsNavHistory.cpp | 56 +++++++++---------- toolkit/components/places/src/nsNavHistory.h | 1 + 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/toolkit/components/places/src/nsNavHistory.cpp b/toolkit/components/places/src/nsNavHistory.cpp index 2fef08f938d..e44af17a62e 100644 --- a/toolkit/components/places/src/nsNavHistory.cpp +++ b/toolkit/components/places/src/nsNavHistory.cpp @@ -879,6 +879,17 @@ nsNavHistory::InitStatements() getter_AddRefs(mDBBookmarkToUrlResult)); NS_ENSURE_SUCCESS(rv, rv); + // mDBURIHasTag + rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( + "SELECT b.id FROM moz_bookmarks b " + "JOIN moz_places p ON b.fk = p.id " + "WHERE p.url = ?1 " + "AND (SELECT b1.parent FROM moz_bookmarks b1 WHERE " + "b1.id = b.parent AND LOWER(b1.title) = LOWER(?2)) = ?3 " + "LIMIT 1"), + getter_AddRefs(mDBURIHasTag)); + NS_ENSURE_SUCCESS(rv, rv); + return NS_OK; } @@ -4098,40 +4109,29 @@ nsNavHistory::GroupByHost(nsNavHistoryQueryResultNode *aResultNode, PRBool nsNavHistory::URIHasTag(nsIURI* aURI, const nsAString& aTag) { - nsresult rv; - nsCOMPtr tagService = - do_GetService(TAGGING_SERVICE_CID, &rv); + mozStorageStatementScoper scoper(mDBURIHasTag); + + nsCAutoString spec; + nsresult rv = aURI->GetSpec(spec); + NS_ENSURE_SUCCESS(rv, rv); + rv = mDBURIHasTag->BindUTF8StringParameter(0, spec); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr tagsV; - rv = tagService->GetTagsForURI(aURI, getter_AddRefs(tagsV)); + rv = mDBURIHasTag->BindStringParameter(1, aTag); NS_ENSURE_SUCCESS(rv, rv); - // confirm that type is array, and has elements - // (data type is different for empty array) - PRUint16 dataType; - tagsV->GetDataType(&dataType); - if (dataType != nsIDataType::VTYPE_ARRAY) - return PR_FALSE; - - // get tags as array - PRUint16 type; - nsIID iid; - PRUint32 count; - PRUnichar** tags; - rv = tagsV->GetAsArray(&type, &iid, &count, (void**)&tags); + nsNavBookmarks* bookmarks = nsNavBookmarks::GetBookmarksService(); + NS_ENSURE_TRUE(bookmarks, NS_ERROR_OUT_OF_MEMORY); + PRInt64 tagRoot; + rv = bookmarks->GetTagRoot(&tagRoot); + NS_ENSURE_SUCCESS(rv, rv); + rv = mDBURIHasTag->BindInt64Parameter(2, tagRoot); NS_ENSURE_SUCCESS(rv, rv); - for (PRUint32 i = 0; i < count; i++) { - nsAutoString tag(tags[i]); - PRInt32 position = Compare(tag, aTag, nsCaseInsensitiveStringComparator()); - if (position == 0) { - nsMemory::Free(tags); - return PR_TRUE; - } - } - nsMemory::Free(tags); - return PR_FALSE; + PRBool hasTag = PR_FALSE; + rv = mDBURIHasTag->ExecuteStep(&hasTag); + NS_ENSURE_SUCCESS(rv, rv); + return hasTag; } diff --git a/toolkit/components/places/src/nsNavHistory.h b/toolkit/components/places/src/nsNavHistory.h index d6f4fbdc6bc..6d49ba9e76b 100644 --- a/toolkit/components/places/src/nsNavHistory.h +++ b/toolkit/components/places/src/nsNavHistory.h @@ -369,6 +369,7 @@ protected: nsCOMPtr mDBGetPageVisitStats; // used by AddVisit nsCOMPtr mDBUpdatePageVisitStats; // used by AddVisit nsCOMPtr mDBAddNewPage; // used by InternalAddNewPage + nsCOMPtr mDBURIHasTag; // used by UriHasTag // these are used by VisitIdToResultNode for making new result nodes from IDs nsCOMPtr mDBVisitToURLResult; // kGetInfoIndex_* results