Bug 1511885 - Stop writing to disk every time a card is accessed. r+a=jorgk
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 05 Dec 2018 16:15:07 +1300
changeset 31989 a85161ecb5ead8f46cd51a37494a9501c5ae8aaa
parent 31988 7afc65db094f2c60dda0e65753d3ddf8b87717a4
child 31990 0f513cd47ccfab640b5e65a27577ed11dc9be03d
push id125
push usermozilla@jorgk.com
push dateSat, 15 Dec 2018 22:50:19 +0000
treeherdercomm-esr60@a85161ecb5ea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1511885
Bug 1511885 - Stop writing to disk every time a card is accessed. r+a=jorgk
mailnews/addrbook/src/nsAbCardProperty.cpp
mailnews/addrbook/src/nsAddrDatabase.cpp
mailnews/addrbook/test/unit/test_uid.js
--- a/mailnews/addrbook/src/nsAbCardProperty.cpp
+++ b/mailnews/addrbook/src/nsAbCardProperty.cpp
@@ -364,17 +364,34 @@ NS_IMETHODIMP nsAbCardProperty::GetUID(n
   id.ToProvidedString(idString);
 
   uid.AppendASCII(idString + 1, NSID_LENGTH - 3);
   return SetUID(uid);
 }
 
 NS_IMETHODIMP nsAbCardProperty::SetUID(const nsACString &aUID)
 {
-  return SetPropertyAsAString(kUIDProperty, NS_ConvertUTF8toUTF16(aUID));
+  nsresult rv = SetPropertyAsAString(kUIDProperty, NS_ConvertUTF8toUTF16(aUID));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (m_directoryId.IsEmpty()) {
+    return NS_OK;
+  }
+
+  int ampIndex = m_directoryId.FindChar('&');
+  const nsACString& directoryId = Substring(m_directoryId, 0, ampIndex);
+
+  nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr <nsIAbDirectory> directory = nullptr;
+  rv = abManager->GetDirectoryFromId(directoryId, getter_AddRefs(directory));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  return directory->ModifyCard(this);
 }
 
 NS_IMETHODIMP nsAbCardProperty::GetFirstName(nsAString &aString)
 {
   nsresult rv = GetPropertyAsAString(kFirstNameProperty, aString);
   if (rv == NS_ERROR_NOT_AVAILABLE)
   {
     aString.Truncate();
--- a/mailnews/addrbook/src/nsAddrDatabase.cpp
+++ b/mailnews/addrbook/src/nsAddrDatabase.cpp
@@ -2220,20 +2220,17 @@ NS_IMETHODIMP nsAddrDatabase::InitCardFr
     }
   } while (true);
 
   uint32_t key = 0;
   rv = GetIntColumn(cardRow, m_RecordKeyColumnToken, &key, 0);
   if (NS_SUCCEEDED(rv))
     newCard->SetPropertyAsUint32(kRecordKeyColumn, key);
 
-  nsAutoCString uid;
-  newCard->GetUID(uid);
-  rv = SetCardValue(newCard, kUIDProperty, NS_ConvertUTF8toUTF16(uid).get(), false);
-  return Commit(nsAddrDBCommitType::kSessionCommit);
+  return NS_OK;
 }
 
 nsresult nsAddrDatabase::GetListCardFromDB(nsIAbCard *listCard, nsIMdbRow* listRow)
 {
   nsresult    err = NS_OK;
   if (!listCard || !listRow)
     return NS_ERROR_NULL_POINTER;
 
--- a/mailnews/addrbook/test/unit/test_uid.js
+++ b/mailnews/addrbook/test/unit/test_uid.js
@@ -40,16 +40,24 @@ add_task(async function existingContactU
   equal(2, bookCards.length, "Loaded test address book");
 
   let card = bookCards[0];
   if (card.isMailList) {
     card = bookCards[1];
   }
   equal(36, card.UID.length, "Existing contact has a UID");
 
+  let existingUID = card.UID;
+  bookCards = [...book.childCards];
+  card = bookCards[0];
+  if (card.isMailList) {
+    card = bookCards[1];
+  }
+  equal(existingUID, card.UID, "New reference to contact has the same UID");
+
   let abFile = profD.clone();
   abFile.append(kPABData.fileName);
   let response = await fetch(Services.io.newFileURI(abFile).spec);
   let text = await response.text();
 
   ok(text.includes(card.UID), "UID has been saved to file");
 });