From 4f48afd990f4d3c7b2c312128e6f508abb6675b5 Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 5 Aug 2010 23:03:30 +0100 Subject: [PATCH] Prevent hammering the grid services with llRequestAgentData requests. Cache the user information permanently, and the online status for 20 seconds. Also cache negatives. --- .../Shared/Api/Implementation/LSL_Api.cs | 48 +++++++++++++++++-- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index eaaa9eb883..15ef98897f 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -68,6 +68,13 @@ using System.Reflection; namespace OpenSim.Region.ScriptEngine.Shared.Api { + // MUST be a ref type + public class UserInfoCacheEntry + { + public int time; + public UserProfileData userProfile; + } + /// /// Contains all LSL ll-functions. This class will be in Default AppDomain. /// @@ -92,6 +99,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api protected int m_scriptConsoleChannel = 0; protected bool m_scriptConsoleChannelEnabled = false; protected IUrlModule m_UrlModule = null; + protected Dictionary m_userInfoCache = + new Dictionary(); public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) { @@ -3885,11 +3894,40 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api UserProfileData userProfile = World.CommsManager.UserService.GetUserProfile(uuid); - UserAgentData userAgent = - World.CommsManager.UserService.GetAgentByUUID(uuid); + UserInfoCacheEntry ce; + if (!m_userInfoCache.TryGetValue(uuid, out ce)) + { + userProfile = World.CommsManager.UserService.GetUserProfile(uuid); + if (userProfile == null) + { + m_userInfoCache[uuid] = null; // Cache negative + return UUID.Zero.ToString(); + } - if (userProfile == null || userAgent == null) - return UUID.Zero.ToString(); + UserAgentData userAgent = + World.CommsManager.UserService.GetAgentByUUID(uuid); + + if (userProfile == null || userAgent == null) + return UUID.Zero.ToString(); + + ce = new UserInfoCacheEntry(); + ce.time = Util.EnvironmentTickCount(); + ce.userProfile = userProfile; + } + else + { + if (ce == null) + return UUID.Zero.ToString(); + + userProfile = ce.userProfile; + } + + if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000) + { + userProfile = World.CommsManager.UserService.GetUserProfile(uuid); + ce.time = Util.EnvironmentTickCount(); + ce.userProfile = userProfile; + } string reply = String.Empty; @@ -9839,4 +9877,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } } } -} \ No newline at end of file +}