reduce number of useless strings on get displaynames cap

This commit is contained in:
UbitUmarov
2022-03-15 00:44:12 +00:00
parent f14055b6a8
commit 476ea2b51d
3 changed files with 126 additions and 18 deletions

View File

@@ -2297,7 +2297,7 @@ namespace OpenSim.Region.ClientStack.Linden
}
else
{
Dictionary<UUID, string> names = m_UserManager.GetKnownUserNames(ids, m_scopeID);
List<UserData> 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<UUID,string> 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);
}

View File

@@ -656,6 +656,122 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
return ret;
}
public List<UserData> GetKnownUsers(string[] ids, UUID scopeID)
{
if (m_Scenes.Count <= 0)
return new List<UserData>();
var ret = new List<UserData>(ids.Length);
List<string> missing = new List<string>(ids.Length);
var untried = new Dictionary<UUID, UserData>();
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<UserAccount> 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)

View File

@@ -48,6 +48,7 @@ namespace OpenSim.Framework
string GetUserServerURL(UUID uuid, string serverType, out bool failedWeb);
Dictionary<UUID, string> GetUsersNames(string[] ids, UUID scopeID);
Dictionary<UUID, string> GetKnownUserNames(string[] ids, UUID scopeID);
List<UserData> GetKnownUsers(string[] ids, UUID scopeID);
void UserWebFailed(UUID id);
/// <summary>