From be6fb22d69f4b2438c5a15cd21e90aaf5bc2f34c Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Tue, 2 Jun 2015 15:40:13 -0700 Subject: [PATCH] Mantis #7567. One of the reported log messages showed this: 09:38:40 - [LOGHTTP]: Slow handling of 15572 POST /CAPS/b12c7e98-8261-4953-b7d1-1c414c9893fc FetchInventory2 8acfbca3-13b5-434f-898c-5f4bbe8a76ff from 92.237.199.112:60083 took 62391ms FetchInventory itself wasn't taking advantage of the new inventory API. This commit fixes that. --- .../FetchInventory/FetchInventory2Handler.cs | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs index b67b326163..0832b02865 100644 --- a/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs +++ b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +using System.Reflection; using OpenMetaverse; using OpenMetaverse.StructuredData; using OpenSim.Framework; @@ -34,11 +35,13 @@ using OpenSim.Services.Interfaces; using OSDArray = OpenMetaverse.StructuredData.OSDArray; using OSDMap = OpenMetaverse.StructuredData.OSDMap; +using log4net; + namespace OpenSim.Capabilities.Handlers { public class FetchInventory2Handler { -// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IInventoryService m_inventoryService; private UUID m_agentID; @@ -59,12 +62,32 @@ namespace OpenSim.Capabilities.Handlers string reply; LLSDFetchInventory llsdReply = new LLSDFetchInventory(); + UUID[] itemIDs = new UUID[itemsRequested.Count]; + int i = 0; foreach (OSDMap osdItemId in itemsRequested) { - UUID itemId = osdItemId["item_id"].AsUUID(); + itemIDs[i++] = osdItemId["item_id"].AsUUID(); + } - InventoryItemBase item = m_inventoryService.GetItem(new InventoryItemBase(itemId, m_agentID)); + InventoryItemBase[] items = m_inventoryService.GetMultipleItems(m_agentID, itemIDs); + if (items == null) + { + // OMG!!! One by one!!! This is fallback code, in case the backend isn't updated + m_log.WarnFormat("[FETCH INVENTORY HANDLER]: GetMultipleItems failed. Falling back to fetching inventory items one by one."); + items = new InventoryItemBase[itemsRequested.Count]; + i = 0; + InventoryItemBase item = new InventoryItemBase(); + item.Owner = m_agentID; + foreach (UUID id in itemIDs) + { + item.ID = id; + items[i++] = m_inventoryService.GetItem(item); + } + } + + foreach (InventoryItemBase item in items) + { if (item != null) { // We don't know the agent that this request belongs to so we'll use the agent id of the item