From c77609818d6a4192919b0c3cc8ed54829237da67 Mon Sep 17 00:00:00 2001 From: Gavin Sharp Date: Fri, 16 Jan 2009 14:19:28 -0500 Subject: [PATCH] Bug 471299: retry code and comments in nsUrlClassifierStore::WriteEntry are wrong, r=dcamp --- .../src/nsUrlClassifierDBService.cpp | 51 ++++++++----------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp b/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp index cfcd1132ce1..b5acc5a5abe 100644 --- a/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp +++ b/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp @@ -1937,38 +1937,29 @@ nsUrlClassifierStore::DeleteEntry(nsUrlClassifierEntry& entry) nsresult nsUrlClassifierStore::WriteEntry(nsUrlClassifierEntry& entry) { - PRBool newEntry = (entry.mId == -1); - - if (newEntry) { - // The insert statement chooses a random ID for the entry, which - // might collide. This should be exceedingly rare, but we'll try - // a few times, otherwise assume a real error. - nsresult rv; - for (PRUint32 i = 0; i < 10; i++) { - mozStorageStatementScoper scoper(mInsertStatement); - - rv = BindStatement(entry, mInsertStatement); - NS_ENSURE_SUCCESS(rv, rv); - - rv = mInsertStatement->Execute(); - if (NS_SUCCEEDED(rv)) { - break; - } - } - - NS_ENSURE_SUCCESS(rv, rv); - - PRInt64 rowId; - rv = mConnection->GetLastInsertRowID(&rowId); - NS_ENSURE_SUCCESS(rv, rv); - - if (rowId > PR_UINT32_MAX) { - return NS_ERROR_FAILURE; - } - - entry.mId = rowId; + if (entry.mId != -1) { + // existing entry, just ignore it + return NS_OK; } + mozStorageStatementScoper scoper(mInsertStatement); + + nsresult rv = BindStatement(entry, mInsertStatement); + NS_ENSURE_SUCCESS(rv, rv); + + rv = mInsertStatement->Execute(); + NS_ENSURE_SUCCESS(rv, rv); + + PRInt64 rowId; + rv = mConnection->GetLastInsertRowID(&rowId); + NS_ENSURE_SUCCESS(rv, rv); + + if (rowId > PR_UINT32_MAX) { + return NS_ERROR_FAILURE; + } + + entry.mId = rowId; + return NS_OK; }