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 33023 a2bd632a970bd5cd9988a6ba3812a0e09cbbd22b
parent 33022 a0750c375f718cc3d9ccfa58749698c4291f5edc
child 33024 e2a06105446af2ccbcad99fc49b90e607ca07208
push id2344
push usermozilla@jorgk.com
push dateWed, 12 Dec 2018 15:02:35 +0000
treeherdercomm-beta@5a1af52c188e [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
@@ -2225,20 +2225,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
@@ -35,16 +35,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");
 });