From bac53387a9868f3765175179aecd3b97981d54a0 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 3 Jun 2015 17:42:41 -0700 Subject: Mantis #7567: added an 8-sec expiring item cache to the inventory network connector. This fixed the problem on my local test grid and generally made things faster. This cache has been needed for a while... there are many parts in the code where the sim gets an item multiple times in a short amount of time (rezzing attachs and objects, for example). Other minor changes: - added the scene as a parameter to the constructor od FetchInvDescHandler, so that I could see in which scene the handler was being called - brought linked items in linked folders back to being prefetched --- .../Inventory/XInventoryServicesConnector.cs | 37 ++++++++++++++++++---- 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'OpenSim/Services/Connectors') diff --git a/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs b/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs index db3c857..b123e9d 100644 --- a/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs +++ b/OpenSim/Services/Connectors/Inventory/XInventoryServicesConnector.cs @@ -62,6 +62,9 @@ namespace OpenSim.Services.Connectors /// private int m_requestTimeoutSecs = -1; + private const double CACHE_EXPIRATION_SECONDS = 8.0; + private ExpiringCache m_ItemCache = new ExpiringCache(); + public XInventoryServicesConnector() { } @@ -511,6 +514,10 @@ namespace OpenSim.Services.Connectors public InventoryItemBase GetItem(InventoryItemBase item) { + InventoryItemBase retrieved = null; + if (m_ItemCache.TryGetValue(item.ID, out retrieved)) + return retrieved; + try { Dictionary ret = MakeRequest("GETITEM", @@ -521,39 +528,57 @@ namespace OpenSim.Services.Connectors if (!CheckReturn(ret)) return null; - return BuildItem((Dictionary)ret["item"]); + retrieved = BuildItem((Dictionary)ret["item"]); } catch (Exception e) { m_log.Error("[XINVENTORY SERVICES CONNECTOR]: Exception in GetItem: ", e); } - return null; + m_ItemCache.AddOrUpdate(item.ID, retrieved, CACHE_EXPIRATION_SECONDS); + + return retrieved; } public virtual InventoryItemBase[] GetMultipleItems(UUID principalID, UUID[] itemIDs) { InventoryItemBase[] itemArr = new InventoryItemBase[itemIDs.Length]; + // Try to get them from the cache + List pending = new List(); + InventoryItemBase item = null; + int i = 0; + foreach (UUID id in itemIDs) + { + if (m_ItemCache.TryGetValue(id, out item)) + itemArr[i++] = item; + else + pending.Add(id); + } + try { Dictionary resultSet = MakeRequest("GETMULTIPLEITEMS", new Dictionary { { "PRINCIPAL", principalID.ToString() }, - { "ITEMS", String.Join(",", itemIDs) }, - { "COUNT", itemIDs.Length.ToString() } + { "ITEMS", String.Join(",", pending.ToArray()) }, + { "COUNT", pending.Count.ToString() } }); if (!CheckReturn(resultSet)) return null; - int i = 0; + // carry over index i where we left above foreach (KeyValuePair kvp in resultSet) { InventoryCollection inventory = new InventoryCollection(); if (kvp.Key.StartsWith("item_")) { if (kvp.Value is Dictionary) - itemArr[i++] = BuildItem((Dictionary)kvp.Value); + { + item = BuildItem((Dictionary)kvp.Value); + m_ItemCache.AddOrUpdate(item.ID, item, CACHE_EXPIRATION_SECONDS); + itemArr[i++] = item; + } else itemArr[i++] = null; } -- cgit v1.1