Prevent hammering the grid services with llRequestAgentData requests. Cache the

user information permanently, and the online status for 20 seconds. Also
cache negatives.
avinationmerge
Melanie Thielker 2010-08-05 22:50:09 +02:00
parent 8bdbcda2b7
commit d8f9b98c4a
1 changed files with 50 additions and 9 deletions

View File

@ -69,6 +69,14 @@ using System.Reflection;
namespace OpenSim.Region.ScriptEngine.Shared.Api namespace OpenSim.Region.ScriptEngine.Shared.Api
{ {
// MUST be a ref type
public class UserInfoCacheEntry
{
public int time;
public UserAccount account;
public PresenceInfo pinfo;
}
/// <summary> /// <summary>
/// Contains all LSL ll-functions. This class will be in Default AppDomain. /// Contains all LSL ll-functions. This class will be in Default AppDomain.
/// </summary> /// </summary>
@ -93,6 +101,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
protected int m_scriptConsoleChannel = 0; protected int m_scriptConsoleChannel = 0;
protected bool m_scriptConsoleChannelEnabled = false; protected bool m_scriptConsoleChannelEnabled = false;
protected IUrlModule m_UrlModule = null; protected IUrlModule m_UrlModule = null;
protected Dictionary<UUID, UserInfoCacheEntry> m_userInfoCache =
new Dictionary<UUID, UserInfoCacheEntry>();
public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID) public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID)
{ {
@ -4244,16 +4254,47 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
UUID uuid = (UUID)id; UUID uuid = (UUID)id;
UserAccount account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
if (account == null)
return UUID.Zero.ToString();
PresenceInfo pinfo = null; PresenceInfo pinfo = null;
PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); UserAccount account;
if (pinfos != null && pinfos.Length > 0)
pinfo = pinfos[0]; UserInfoCacheEntry ce;
if (!m_userInfoCache.TryGetValue(uuid, out ce))
{
account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid);
if (account == null)
{
m_userInfoCache[uuid] = null; // Cache negative
return UUID.Zero.ToString();
}
PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
if (pinfos != null && pinfos.Length > 0)
pinfo = pinfos[0];
ce = new UserInfoCacheEntry();
ce.time = Util.EnvironmentTickCount();
ce.account = account;
ce.pinfo = pinfo;
}
else
{
if (ce == null)
return UUID.Zero.ToString();
account = ce.account;
pinfo = ce.pinfo;
}
if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000)
{
PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() });
if (pinfos != null && pinfos.Length > 0)
pinfo = pinfos[0];
ce.time = Util.EnvironmentTickCount();
ce.pinfo = pinfo;
}
string reply = String.Empty; string reply = String.Empty;