fix for bug #386956: Simplify nsNavHistory::RemoveDuplicateURLs

patch=Marcho Bonardo <mak77@supereva.it>
r=sspitzer
This commit is contained in:
sspitzer@mozilla.org 2007-07-12 16:49:58 -07:00
Родитель fffff1bde0
Коммит 0e27853da4
1 изменённых файлов: 14 добавлений и 47 удалений

Просмотреть файл

@ -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<mozIStorageStatement> 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<PRInt64> 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<mozIStorageStatement> 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 **************************************************************