From 476ea2b51da954180e34662bb036f16a477b838e Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 15 Mar 2022 00:44:12 +0000 Subject: [PATCH] reduce number of useless strings on get displaynames cap --- .../Linden/Caps/BunchOfCaps/BunchOfCaps.cs | 27 ++-- .../UserManagement/UserManagementModule.cs | 116 ++++++++++++++++++ .../Services/Interfaces/IUserManagement.cs | 1 + 3 files changed, 126 insertions(+), 18 deletions(-) diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index 5a7256cd59..15d32d18c3 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs @@ -2297,7 +2297,7 @@ namespace OpenSim.Region.ClientStack.Linden } else { - Dictionary names = m_UserManager.GetKnownUserNames(ids, m_scopeID); + List names = m_UserManager.GetKnownUsers(ids, m_scopeID); lsl = LLSDxmlEncode2.Start(names.Count * 256 + 256); LLSDxmlEncode2.AddMap(lsl); @@ -2307,30 +2307,21 @@ namespace OpenSim.Region.ClientStack.Linden { LLSDxmlEncode2.AddArray("agents", lsl); - foreach (KeyValuePair kvp in names) + foreach (UserData ud in names) { - if(kvp.Key.IsZero()) - continue; - - string fullname = kvp.Value; // dont tell about unknown users, we can't send them back on Bad either - if (string.IsNullOrEmpty(fullname)) - continue; - string[] parts = fullname.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); - if(string.IsNullOrEmpty(parts[0]) || parts[0].Equals("Unknown")) + if (string.IsNullOrEmpty(ud.FirstName) || ud.FirstName.Equals("Unkown")) continue; + string fullname = ud.FirstName + " " + ud.LastName; LLSDxmlEncode2.AddMap(lsl); + LLSDxmlEncode2.AddElem("username", fullname, lsl); + LLSDxmlEncode2.AddElem("display_name", fullname, lsl); LLSDxmlEncode2.AddElem("display_name_next_update", DateTime.UtcNow.AddDays(8), lsl); LLSDxmlEncode2.AddElem("display_name_expires", DateTime.UtcNow.AddMonths(1), lsl); - LLSDxmlEncode2.AddElem("display_name", fullname, lsl); - LLSDxmlEncode2.AddElem("legacy_first_name", parts[0], lsl); - if (string.IsNullOrEmpty(parts[1])) - LLSDxmlEncode2.AddElem("legacy_last_name", "", lsl); - else - LLSDxmlEncode2.AddElem("legacy_last_name", parts[1], lsl); - LLSDxmlEncode2.AddElem("username", fullname, lsl); - LLSDxmlEncode2.AddElem("id", kvp.Key, lsl); + LLSDxmlEncode2.AddElem("legacy_first_name", ud.FirstName, lsl); + LLSDxmlEncode2.AddElem("legacy_last_name", ud.LastName, lsl); + LLSDxmlEncode2.AddElem("id", ud.Id, lsl); LLSDxmlEncode2.AddElem("is_display_name_default", true, lsl); LLSDxmlEncode2.AddEndMap(lsl); } diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs index 4be3384296..d20f798321 100755 --- a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs +++ b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs @@ -656,6 +656,122 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement return ret; } + public List GetKnownUsers(string[] ids, UUID scopeID) + { + if (m_Scenes.Count <= 0) + return new List(); + + var ret = new List(ids.Length); + + List missing = new List(ids.Length); + var untried = new Dictionary(); + foreach (string id in ids) + { + if (!UUID.TryParse(id, out UUID uuid) || uuid.IsZero()) + continue; + + if (m_userCacheByID.TryGetValue(uuid, out UserData userdata)) + { + if (userdata.HasGridUserTried) + { + if (!userdata.IsUnknownUser) + ret.Add(userdata); + continue; + } + else + untried[uuid] = userdata; + } + missing.Add(id); + } + + if (missing.Count == 0) + return ret; + + ids = null; + + List accounts = m_userAccountService.GetUserAccounts(scopeID, missing); + if (accounts.Count != 0) + { + foreach (UserAccount uac in accounts) + { + if (uac != null) + { + UUID id = uac.PrincipalID; + + var userdata = new UserData(); + userdata.Id = id; + userdata.FirstName = uac.FirstName; + userdata.LastName = uac.LastName; + userdata.HomeURL = string.Empty; + userdata.IsUnknownUser = false; + userdata.IsLocal = true; + userdata.HasGridUserTried = true; + m_userCacheByID.Add(id, userdata, 1800000); + + ret.Add(userdata); + missing.Remove(id.ToString()); // slowww + untried.Remove(id); + } + } + } + + if (missing.Count == 0 || m_gridUserService == null) + return ret; + + GridUserInfo[] pinfos = m_gridUserService.GetGridUserInfo(missing.ToArray()); + missing = null; + if (pinfos.Length > 0) + { + foreach (GridUserInfo uInfo in pinfos) + { + if (uInfo != null && uInfo.UserID.Length >= 36) + { + if (Util.ParseFullUniversalUserIdentifier(uInfo.UserID, out UUID uuid, out string url, out string first, out string last)) + { + bool isvalid = CheckUrl(url, out bool islocal, out OSHHTPHost host); + var userdata = new UserData(); + userdata.Id = uuid; + if (isvalid) + { + if (islocal) + { + userdata.FirstName = first; + userdata.LastName = last; + userdata.HomeURL = string.Empty; + userdata.IsLocal = true; + } + else + { + userdata.FirstName = first.Replace(" ", ".") + "." + last.Replace(" ", "."); + userdata.HomeURL = host.URI; + userdata.LastName = "@" + host.HostAndPort; + userdata.IsLocal = false; + } + + userdata.IsUnknownUser = false; + userdata.HasGridUserTried = true; + m_userCacheByID.Add(uuid, userdata, 1800000); + + untried.Remove(uuid); + ret.Add(userdata); + } + } + else + m_log.DebugFormat("[USER MANAGEMENT MODULE]: Unable to parse UUI {0}", uInfo.UserID); + } + } + } + + foreach (UserData ud in untried.Values) + { + ud.HasGridUserTried = true; + m_userCacheByID.Add(ud.Id, ud, 1800000); + if (!ud.IsUnknownUser) + ret.Add(ud); + } + return ret; + } + public virtual string GetUserHomeURL(UUID userID) { if (GetUser(userID, out UserData user) && user != null) diff --git a/OpenSim/Services/Interfaces/IUserManagement.cs b/OpenSim/Services/Interfaces/IUserManagement.cs index 3abbc151f2..c09788bbd9 100644 --- a/OpenSim/Services/Interfaces/IUserManagement.cs +++ b/OpenSim/Services/Interfaces/IUserManagement.cs @@ -48,6 +48,7 @@ namespace OpenSim.Framework string GetUserServerURL(UUID uuid, string serverType, out bool failedWeb); Dictionary GetUsersNames(string[] ids, UUID scopeID); Dictionary GetKnownUserNames(string[] ids, UUID scopeID); + List GetKnownUsers(string[] ids, UUID scopeID); void UserWebFailed(UUID id); ///