From c53d74274d1fa9e76621206185ee4e1ff3c57f16 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 19 Aug 2016 00:14:46 +0100 Subject: missed another UserAccounts cache, add a few locks --- .../LocalUserAccountServiceConnector.cs | 51 +++++++++++++++++++--- .../RemoteUserAccountServiceConnector.cs | 31 ++++++++++--- 2 files changed, 69 insertions(+), 13 deletions(-) (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut') diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs index 1bb4704..3127199 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs @@ -153,12 +153,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts public UserAccount GetUserAccount(UUID scopeID, UUID userID) { bool inCache = false; - UserAccount account = m_Cache.Get(userID, out inCache); + UserAccount account; + lock(m_Cache) + account = m_Cache.Get(userID, out inCache); if (inCache) return account; account = UserAccountService.GetUserAccount(scopeID, userID); - m_Cache.Cache(userID, account); + lock(m_Cache) + m_Cache.Cache(userID, account); return account; } @@ -166,13 +169,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts public UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName) { bool inCache = false; - UserAccount account = m_Cache.Get(firstName + " " + lastName, out inCache); + UserAccount account; + lock(m_Cache) + account = m_Cache.Get(firstName + " " + lastName, out inCache); if (inCache) return account; account = UserAccountService.GetUserAccount(scopeID, firstName, lastName); if (account != null) - m_Cache.Cache(account.PrincipalID, account); + lock(m_Cache) + m_Cache.Cache(account.PrincipalID, account); return account; } @@ -184,9 +190,42 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts public List GetUserAccounts(UUID scopeID, List IDs) { - return UserAccountService.GetUserAccounts(scopeID, IDs); - } + List ret = new List(); + List missing = new List(); + + // still another cache.. + bool inCache = false; + UUID uuid = UUID.Zero; + UserAccount account; + foreach(string id in IDs) + { + if(UUID.TryParse(id, out uuid)) + { + lock(m_Cache) + account = m_Cache.Get(uuid, out inCache); + if (inCache) + ret.Add(account); + else + missing.Add(id); + } + } + if(missing.Count == 0) + return ret; + + List ext = UserAccountService.GetUserAccounts(scopeID, missing); + if(ext != null && ext.Count > 0) + { + ret.AddRange(ext); + foreach(UserAccount acc in ext) + { + if(acc != null) + lock(m_Cache) + m_Cache.Cache(acc.PrincipalID, acc); + } + } + return ret; + } public List GetUserAccountsWhere(UUID scopeID, string query) { diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs index 90c90d6..eead05d 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs @@ -128,7 +128,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts // flags, title, etc. And country, don't forget country! private void OnNewClient(IClientAPI client) { - m_Cache.Remove(client.Name); + lock(m_Cache) + m_Cache.Remove(client.Name); } #region Overwritten methods from IUserAccountService @@ -136,12 +137,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts public override UserAccount GetUserAccount(UUID scopeID, UUID userID) { bool inCache = false; - UserAccount account = m_Cache.Get(userID, out inCache); + UserAccount account; + lock(m_Cache) + account = m_Cache.Get(userID, out inCache); if (inCache) return account; account = base.GetUserAccount(scopeID, userID); - m_Cache.Cache(userID, account); + lock(m_Cache) + if(account != null) + m_Cache.Cache(userID, account); return account; } @@ -149,13 +154,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts public override UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName) { bool inCache = false; - UserAccount account = m_Cache.Get(firstName + " " + lastName, out inCache); + UserAccount account; + lock(m_Cache) + account = m_Cache.Get(firstName + " " + lastName, out inCache); if (inCache) return account; account = base.GetUserAccount(scopeID, firstName, lastName); if (account != null) - m_Cache.Cache(account.PrincipalID, account); + lock(m_Cache) + m_Cache.Cache(account.PrincipalID, account); return account; } @@ -173,7 +181,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts { if(UUID.TryParse(id, out uuid)) { - account = m_Cache.Get(uuid, out inCache); + lock(m_Cache) + account = m_Cache.Get(uuid, out inCache); if (inCache) accs.Add(account); else @@ -184,8 +193,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts if(missing.Count > 0) { List ext = base.GetUserAccounts(scopeID, missing); - if(ext != null) + if(ext != null && ext.Count >0 ) + { accs.AddRange(ext); + foreach(UserAccount acc in ext) + { + if(acc != null) + lock(m_Cache) + m_Cache.Cache(acc.PrincipalID, acc); + } + } } return accs; -- cgit v1.1