diff --git a/toolkit/components/places/src/nsNavHistory.cpp b/toolkit/components/places/src/nsNavHistory.cpp index 04b8b051429..e09063c73d0 100644 --- a/toolkit/components/places/src/nsNavHistory.cpp +++ b/toolkit/components/places/src/nsNavHistory.cpp @@ -3527,7 +3527,7 @@ nsNavHistory::RecursiveGroup(nsNavHistoryQueryResultNode *aResultNode, if (aGroupCount > 1) { // Sort another level: We need to copy the array since we want the output - // to be our level's destionation arrays. + // to be our level's destination arrays. for (PRInt32 i = 0; i < aDest->Count(); i ++) { nsNavHistoryResultNode* curNode = (*aDest)[i]; if (curNode->IsContainer()) { @@ -4366,61 +4366,28 @@ nsNavHistory::AddPageWithVisit(nsIURI *aURI, NS_ENSURE_SUCCESS(rv, rv); } - return NS_OK; + return NS_OK; } nsresult nsNavHistory::RemoveDuplicateURIs() { - nsCOMPtr statement; - nsresult rv = mDBConn->CreateStatement( - NS_LITERAL_CSTRING("SELECT id, url FROM moz_places ORDER BY url"), - getter_AddRefs(statement)); + // this must be in a transaction because it is made up of 2 related DELETEs + mozStorageTransaction transaction(mDBConn, PR_FALSE); + + // remove all duplicates related visits from history and visit tables. + nsresult rv = mDBConn->ExecuteSimpleSQL( + NS_LITERAL_CSTRING("DELETE FROM moz_historyvisits WHERE place_id IN " + "(SELECT id FROM moz_places GROUP BY url HAVING( COUNT(url) > 1))")); NS_ENSURE_SUCCESS(rv, rv); - nsTArray duplicates; - nsCAutoString lastURI; - PRBool hasMore; - while (NS_SUCCEEDED(statement->ExecuteStep(&hasMore)) && hasMore) { - nsCAutoString uri; - statement->GetUTF8String(1, uri); - if (uri.Equals(lastURI)) { - duplicates.AppendElement(statement->AsInt64(0)); - } else { - lastURI = uri; - } - } - - // Now remove all of the duplicates from the history and visit tables. - rv = mDBConn->CreateStatement( - NS_LITERAL_CSTRING("DELETE FROM moz_places WHERE id = ?1"), - getter_AddRefs(statement)); + // then remove duplicate URIs from places table + rv = mDBConn->ExecuteSimpleSQL( + NS_LITERAL_CSTRING("DELETE FROM moz_places WHERE id IN " + "(SELECT id FROM moz_places GROUP BY url HAVING( COUNT(url) > 1))")); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr visitDelete; - rv = mDBConn->CreateStatement( - NS_LITERAL_CSTRING("DELETE FROM moz_historyvisits WHERE place_id = ?1"), - getter_AddRefs(visitDelete)); - NS_ENSURE_SUCCESS(rv, rv); - - for (PRUint32 i = 0; i < duplicates.Length(); ++i) { - PRInt64 id = duplicates[i]; - { - mozStorageStatementScoper scope(statement); - rv = statement->BindInt64Parameter(0, id); - NS_ENSURE_SUCCESS(rv, rv); - rv = statement->Execute(); - NS_ENSURE_SUCCESS(rv, rv); - } - { - mozStorageStatementScoper scope(visitDelete); - rv = visitDelete->BindInt64Parameter(0, id); - NS_ENSURE_SUCCESS(rv, rv); - rv = visitDelete->Execute(); - NS_ENSURE_SUCCESS(rv, rv); - } - } - return NS_OK; + return transaction.Commit(); } // Local function **************************************************************