From 7ff4c2e50b3df8ea82dc8a27f3b68657fe29226b Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 28 Aug 2009 17:07:17 +0100 Subject: Pull out distinct cache system folders and drop cache methods in InventoryCache --- .../Archiver/Tests/InventoryArchiverTests.cs | 14 ++++++- .../Inventory/InventoryCache.cs | 47 ++++++++++++++++------ .../Services/InventoryService/InventoryService.cs | 2 + .../Tests/Common/Mock/TestInventoryDataPlugin.cs | 12 +++++- 4 files changed, 59 insertions(+), 16 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs index 907c8f4..1696d82 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs @@ -45,6 +45,7 @@ using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver; using OpenSim.Region.CoreModules.World.Serialiser; using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes.Serialization; +using OpenSim.Services.Interfaces; using OpenSim.Tests.Common; using OpenSim.Tests.Common.Mock; using OpenSim.Tests.Common.Setup; @@ -102,6 +103,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests Monitor.Wait(this, 60000); } + Console.WriteLine("here"); + // Create asset SceneObjectGroup object1; SceneObjectPart part1; @@ -135,8 +138,15 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests item1.AssetID = asset1.FullID; item1.ID = item1Id; //userInfo.RootFolder.FindFolderByPath("Objects").ID; - InventoryFolderBase objsFolder = scene.InventoryService.GetFolderForType(userId, AssetType.Object); - //InventoryFolderBase rootFolder = scene.InventoryService.GetRootFolder(userId); + //InventoryFolderBase objsFolder = scene.InventoryService.GetFolderForType(userId, AssetType.Object); + Console.WriteLine("here2"); + IInventoryService inventoryService = scene.InventoryService; + InventoryFolderBase rootFolder = inventoryService.GetRootFolder(userId); + InventoryCollection rootContents = inventoryService.GetFolderContent(userId, rootFolder.ID); + InventoryFolderBase objsFolder = null; + foreach (InventoryFolderBase folder in rootContents.Folders) + if (folder.Name == "Objects") + objsFolder = folder; item1.Folder = objsFolder.ID; scene.AddInventoryItem(userId, item1); diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs index c8f04a5..73ffc5e 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs @@ -88,13 +88,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory } // If not, go get them and place them in the cache - Dictionary folders = m_Connector.GetSystemFolders(presence.UUID); + Dictionary folders = CacheSystemFolders(presence.UUID); m_log.DebugFormat("[INVENTORY CACHE]: OnMakeRootAgent in {0}, fetched system folders for {1} {2}: count {3}", presence.Scene.RegionInfo.RegionName, presence.Firstname, presence.Lastname, folders.Count); - - if (folders.Count > 0) - lock (m_InventoryCache) - m_InventoryCache.Add(presence.UUID, folders); } void OnClientClosed(UUID clientID, Scene scene) @@ -113,26 +109,51 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory } } - // Drop system folders + m_log.DebugFormat( + "[INVENTORY CACHE]: OnClientClosed in {0}, user {1} out of sim. Dropping system folders", + scene.RegionInfo.RegionName, clientID); + DropCachedSystemFolders(clientID); + } + } + + /// + /// Cache a user's 'system' folders. + /// + /// + /// Folders cached + protected Dictionary CacheSystemFolders(UUID userID) + { + // If not, go get them and place them in the cache + Dictionary folders = m_Connector.GetSystemFolders(userID); + + if (folders.Count > 0) lock (m_InventoryCache) - if (m_InventoryCache.ContainsKey(clientID)) - { - m_log.DebugFormat("[INVENTORY CACHE]: OnClientClosed in {0}, user {1} out of sim. Dropping system folders", - scene.RegionInfo.RegionName, clientID); + m_InventoryCache.Add(userID, folders); - m_InventoryCache.Remove(clientID); - } - } + return folders; } + /// + /// Drop a user's cached 'system' folders + /// + /// + protected void DropCachedSystemFolders(UUID userID) + { + // Drop system folders + lock (m_InventoryCache) + if (m_InventoryCache.ContainsKey(userID)) + m_InventoryCache.Remove(userID); + } public InventoryFolderBase GetFolderForType(UUID userID, AssetType type) { Dictionary folders = null; + lock (m_InventoryCache) { m_InventoryCache.TryGetValue(userID, out folders); } + if ((folders != null) && folders.ContainsKey(type)) { return folders[type]; diff --git a/OpenSim/Services/InventoryService/InventoryService.cs b/OpenSim/Services/InventoryService/InventoryService.cs index 19b1fd8..f04754b 100644 --- a/OpenSim/Services/InventoryService/InventoryService.cs +++ b/OpenSim/Services/InventoryService/InventoryService.cs @@ -88,6 +88,8 @@ namespace OpenSim.Services.InventoryService // See IInventoryServices public virtual InventoryFolderBase GetRootFolder(UUID userID) { + //m_log.DebugFormat("[INVENTORY SERVICE]: Getting root folder for {0}", userID); + // Retrieve the first root folder we get from the DB. InventoryFolderBase rootFolder = m_Database.getUserRootFolder(userID); if (rootFolder != null) diff --git a/OpenSim/Tests/Common/Mock/TestInventoryDataPlugin.cs b/OpenSim/Tests/Common/Mock/TestInventoryDataPlugin.cs index 1b14abb..ce116f2 100644 --- a/OpenSim/Tests/Common/Mock/TestInventoryDataPlugin.cs +++ b/OpenSim/Tests/Common/Mock/TestInventoryDataPlugin.cs @@ -27,6 +27,8 @@ using System; using System.Collections.Generic; +using System.Reflection; +using log4net; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Data; @@ -39,7 +41,9 @@ namespace OpenSim.Tests.Common.Mock /// tests are single threaded. /// public class TestInventoryDataPlugin : IInventoryDataPlugin - { + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + /// /// Inventory folders /// @@ -87,6 +91,8 @@ namespace OpenSim.Tests.Common.Mock public InventoryFolderBase getUserRootFolder(UUID user) { + m_log.DebugFormat("[MOCK INV DB]: Looking for root folder for {0}", user); + InventoryFolderBase folder = null; m_rootFolders.TryGetValue(user, out folder); @@ -124,7 +130,11 @@ namespace OpenSim.Tests.Common.Mock m_folders[folder.ID] = folder; if (folder.ParentID == UUID.Zero) + { + m_log.DebugFormat( + "[MOCK INV DB]: Adding root folder {0} {1} for {2}", folder.Name, folder.ID, folder.Owner); m_rootFolders[folder.Owner] = folder; + } } public void updateInventoryFolder(InventoryFolderBase folder) -- cgit v1.1