From a9c3681cb5eecc043dab3f5c9dc9d97bc1af1075 Mon Sep 17 00:00:00 2001
From: Merov Linden <merov@lindenlab.com>
Date: Fri, 10 Apr 2015 17:37:11 -0700
Subject: DD-381 : Avoid unecessary SLM updates, suppress some
 update_marketplace_category() that are picked by dirty bit setup

---
 indra/newview/llinventorybridge.cpp      |  2 --
 indra/newview/llinventoryfunctions.cpp   |  5 -----
 indra/newview/llmarketplacefunctions.cpp | 27 +++++++++++++++++++++++++--
 3 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/indra/newview/llinventorybridge.cpp b/indra/newview/llinventorybridge.cpp
index b7b2d1b285..df07c06467 100755
--- a/indra/newview/llinventorybridge.cpp
+++ b/indra/newview/llinventorybridge.cpp
@@ -4675,8 +4675,6 @@ BOOL LLFolderBridge::dragItemIntoFolder(LLInventoryItem* inv_item,
                         LLMarketplaceData::instance().activateListing(version_folder_id,false);
                     }
                 }
-                // Update the listing we moved from anyway
-                update_marketplace_category(from_folder_uuid);
             }
 
 			//
diff --git a/indra/newview/llinventoryfunctions.cpp b/indra/newview/llinventoryfunctions.cpp
index 123e55a8ee..135b6f2f17 100755
--- a/indra/newview/llinventoryfunctions.cpp
+++ b/indra/newview/llinventoryfunctions.cpp
@@ -1505,11 +1505,6 @@ bool move_item_to_marketplacelistings(LLInventoryItem* inv_item, LLUUID dest_fol
                 // Reparent the item
                 gInventory.changeItemParent(viewer_inv_item, dest_folder, true);
             }
-            
-            // Update the modified folders
-            update_marketplace_category(src_folder);
-            update_marketplace_category(dest_folder);
-            gInventory.notifyObservers();
         }
         else
         {
diff --git a/indra/newview/llmarketplacefunctions.cpp b/indra/newview/llmarketplacefunctions.cpp
index 5d8bab5833..de3bd35de0 100755
--- a/indra/newview/llmarketplacefunctions.cpp
+++ b/indra/newview/llmarketplacefunctions.cpp
@@ -1507,6 +1507,12 @@ bool LLMarketplaceData::activateListing(const LLUUID& folder_id, bool activate)
         return false;
     }
     
+    if (getActivationState(listing_uuid) == activate)
+    {
+        // If activation state is unchanged, no point spamming SLM with an update
+        return true;
+    }
+    
     LLUUID version_uuid = getVersionFolder(listing_uuid);
     
     // Also update the count on hand
@@ -1530,6 +1536,12 @@ bool LLMarketplaceData::setVersionFolder(const LLUUID& folder_id, const LLUUID&
         return false;
     }
     
+    if (getVersionFolder(listing_uuid) == version_id)
+    {
+        // If version folder is unchanged, no point spamming SLM with an update
+        return true;
+    }
+    
     // Note: if the version_id is cleared, we need to unlist the listing, otherwise, state unchanged
     bool is_listed = (version_id.isNull() ? false : getActivationState(listing_uuid));
     
@@ -1554,16 +1566,27 @@ bool LLMarketplaceData::updateCountOnHand(const LLUUID& folder_id)
         return false;
     }
     
+    // Compute the new count on hand
+    S32 count = compute_stock_count(folder_id);
+
+    if (getCountOnHand(listing_uuid) == count)
+    {
+        // If count on hand is unchanged, no point spamming SLM with an update
+        return true;
+    }
+    
     // Get the unchanged values
     bool is_listed = getActivationState(listing_uuid);
     LLUUID version_uuid = getVersionFolder(listing_uuid);
 
-    // Compute the new count on hand
-    S32 count = compute_stock_count(folder_id);
     
     // Post the listing update request to SLM
     updateSLMListing(listing_uuid, listing_id, version_uuid, is_listed, count);
     
+    // Force the local value as it prevents spamming (count update may occur in burst when restocking)
+    // Note that if SLM has a good reason to return a different value, it'll be updated by the responder
+    setCountOnHand(listing_uuid, count, false);
+
     return true;
 }
 
-- 
cgit v1.2.3