Bug 426991 - Form submission extremely slow on large forms (with form Form history turned on). r=sdwilsh, r=gavin
authorJustin Dolske <dolske@mozilla.com>
Fri, 10 Oct 2008 14:51:49 -0700
changeset 20281 c6e5382e72e159dc2fd37db2e16638d4c1bd03c3
parent 20280 c98392bd35b3e31ead029972452867098fddd1f8
child 20282 13098edfa017f100d08e87a7b5e116b74720a35c
push id2768
push userjdolske@mozilla.com
push dateFri, 10 Oct 2008 21:51:54 +0000
treeherdermozilla-central@c6e5382e72e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssdwilsh, gavin
bugs426991
milestone1.9.1b2pre
Bug 426991 - Form submission extremely slow on large forms (with form Form history turned on). r=sdwilsh, r=gavin
toolkit/components/satchel/src/nsStorageFormHistory.cpp
--- a/toolkit/components/satchel/src/nsStorageFormHistory.cpp
+++ b/toolkit/components/satchel/src/nsStorageFormHistory.cpp
@@ -222,32 +222,30 @@ nsFormHistory::GetHasEntries(PRBool *aHa
 }
 
 NS_IMETHODIMP
 nsFormHistory::AddEntry(const nsAString &aName, const nsAString &aValue)
 {
   if (!FormHistoryEnabled())
     return NS_OK;
 
-  mozStorageTransaction transaction(mDBConn, PR_FALSE);
-
   PRBool exists = PR_TRUE;
   EntryExists(aName, aValue, &exists);
   if (!exists) {
     mozStorageStatementScoper scope(mDBInsertNameValue);
     nsresult rv = mDBInsertNameValue->BindStringParameter(0, aName);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = mDBInsertNameValue->BindStringParameter(1, aValue);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = mDBInsertNameValue->Execute();
     NS_ENSURE_SUCCESS(rv, rv);
   }
-  return transaction.Commit();
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsFormHistory::EntryExists(const nsAString &aName, 
                            const nsAString &aValue, PRBool *_retval)
 {
   mozStorageStatementScoper scope(mDBFindEntry);
 
@@ -361,16 +359,20 @@ nsFormHistory::Notify(nsIDOMHTMLFormElem
   if (autocomplete.LowerCaseEqualsLiteral("off"))
     return NS_OK;
 
   nsCOMPtr<nsIDOMHTMLCollection> elts;
   formElt->GetElements(getter_AddRefs(elts));
 
   PRUint32 length;
   elts->GetLength(&length);
+  if (length == 0)
+    return NS_OK;
+
+  mozStorageTransaction transaction(mDBConn, PR_FALSE);
   for (PRUint32 i = 0; i < length; ++i) {
     nsCOMPtr<nsIDOMNode> node;
     elts->Item(i, getter_AddRefs(node));
     nsCOMPtr<nsIDOMHTMLInputElement> inputElt = do_QueryInterface(node);
     if (inputElt) {
       // Filter only inputs that are of type "text" without autocomplete="off"
       nsAutoString type;
       inputElt->GetType(type);
@@ -393,17 +395,17 @@ nsFormHistory::Notify(nsIDOMHTMLFormElem
             inputElt->GetId(name);
           if (!name.IsEmpty())
             AddEntry(name, value);
         }
       }
     }
   }
 
-  return NS_OK;
+  return transaction.Commit();
 }
 nsresult
 nsFormHistory::OpenDatabase()
 {
   // init DB service and obtain a connection
   nsresult rv;
   mStorageService = do_GetService(MOZ_STORAGE_SERVICE_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);