mirror of
https://github.com/opensim/opensim.git
synced 2026-08-05 08:55:56 +08:00
mantis 8802 and 6744: change how griduserservice handles duplicated entries, trying to use the most recent. Add cache to compensate the very low performance of the search the db engine is force to do. WARNING this is not compatible with current Diva Wifi. that will replace this code or not run at all
This commit is contained in:
@@ -126,38 +126,54 @@ namespace OpenSim.Services.UserAccountService
|
||||
MainConsole.Instance.Output("Users online: {0}", onlineRecentlyCount);
|
||||
}
|
||||
|
||||
private static ExpiringCacheOS<string, GridUserData> cache = new ExpiringCacheOS<string, GridUserData>(00000);
|
||||
private GridUserData GetGridUserData(string userID)
|
||||
{
|
||||
GridUserData d = null;
|
||||
if (userID.Length > 36) // it's a UUI
|
||||
{
|
||||
d = m_Database.Get(userID);
|
||||
}
|
||||
else // it's a UUID
|
||||
{
|
||||
GridUserData[] ds = m_Database.GetAll(userID);
|
||||
if (ds == null)
|
||||
return null;
|
||||
if (userID.Length > 36)
|
||||
userID = userID.Substring(0, 36);
|
||||
|
||||
if (ds.Length > 0)
|
||||
if (cache.TryGetValue(userID, out GridUserData d))
|
||||
return d;
|
||||
|
||||
GridUserData[] ds = m_Database.GetAll(userID);
|
||||
if (ds == null || ds.Length == 0)
|
||||
{
|
||||
cache.Add(userID, null, 300000);
|
||||
return null;
|
||||
}
|
||||
|
||||
d = ds[0];
|
||||
if (ds.Length > 1)
|
||||
{
|
||||
// try find most recent record
|
||||
try
|
||||
{
|
||||
d = ds[0];
|
||||
foreach (GridUserData dd in ds)
|
||||
if (dd.UserID.Length > d.UserID.Length) // find the longest
|
||||
d = dd;
|
||||
}
|
||||
}
|
||||
int tsta = int.Parse(d.Data["Login"]);
|
||||
int tstb = int.Parse(d.Data["Logout"]);
|
||||
int cur = tstb > tsta? tstb : tsta;
|
||||
|
||||
for (int i = 1; i < ds.Length; ++i)
|
||||
{
|
||||
GridUserData dd = ds[i];
|
||||
tsta = int.Parse(dd.Data["Login"]);
|
||||
tstb = int.Parse(dd.Data["Logout"]);
|
||||
if(tsta > tstb)
|
||||
tstb = tsta;
|
||||
if (tstb > cur)
|
||||
{
|
||||
cur = tstb;
|
||||
d = dd;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
cache.Add(userID, d, 300000);
|
||||
return d;
|
||||
}
|
||||
|
||||
public virtual GridUserInfo GetGridUserInfo(string userID)
|
||||
private GridUserInfo ToInfo(GridUserData d)
|
||||
{
|
||||
GridUserData d = GetGridUserData(userID);
|
||||
|
||||
if (d == null)
|
||||
return null;
|
||||
|
||||
GridUserInfo info = new GridUserInfo();
|
||||
info.UserID = d.UserID;
|
||||
info.HomeRegionID = new UUID(d.Data["HomeRegionID"]);
|
||||
@@ -171,10 +187,19 @@ namespace OpenSim.Services.UserAccountService
|
||||
info.Online = bool.Parse(d.Data["Online"]);
|
||||
info.Login = Util.ToDateTime(Convert.ToInt32(d.Data["Login"]));
|
||||
info.Logout = Util.ToDateTime(Convert.ToInt32(d.Data["Logout"]));
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
public virtual GridUserInfo GetGridUserInfo(string userID)
|
||||
{
|
||||
GridUserData d = GetGridUserData(userID);
|
||||
|
||||
if (d == null)
|
||||
return null;
|
||||
|
||||
return ToInfo(d);
|
||||
}
|
||||
|
||||
public virtual GridUserInfo[] GetGridUserInfo(string[] userIDs)
|
||||
{
|
||||
List<GridUserInfo> ret = new List<GridUserInfo>();
|
||||
@@ -201,8 +226,10 @@ namespace OpenSim.Services.UserAccountService
|
||||
d.Data["Login"] = Util.UnixTimeSinceEpoch().ToString();
|
||||
|
||||
m_Database.Store(d);
|
||||
if (userID.Length >= 36)
|
||||
cache.Add(userID.Substring(0, 36), d, 300000);
|
||||
|
||||
return GetGridUserInfo(userID);
|
||||
return ToInfo(d);
|
||||
}
|
||||
|
||||
public bool LoggedOut(string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
|
||||
@@ -223,7 +250,10 @@ namespace OpenSim.Services.UserAccountService
|
||||
d.Data["LastPosition"] = lastPosition.ToString();
|
||||
d.Data["LastLookAt"] = lastLookAt.ToString();
|
||||
|
||||
return m_Database.Store(d);
|
||||
bool ret = m_Database.Store(d);
|
||||
if (ret && userID.Length >= 36)
|
||||
cache.Add(userID.Substring(0, 36), d, 300000);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public bool SetHome(string userID, UUID homeID, Vector3 homePosition, Vector3 homeLookAt)
|
||||
@@ -240,7 +270,10 @@ namespace OpenSim.Services.UserAccountService
|
||||
d.Data["HomePosition"] = homePosition.ToString();
|
||||
d.Data["HomeLookAt"] = homeLookAt.ToString();
|
||||
|
||||
return m_Database.Store(d);
|
||||
bool ret = m_Database.Store(d);
|
||||
if (ret && userID.Length >= 36)
|
||||
cache.Add(userID.Substring(0, 36), d, 300000);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public bool SetLastPosition(string userID, UUID sessionID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt)
|
||||
@@ -259,7 +292,10 @@ namespace OpenSim.Services.UserAccountService
|
||||
d.Data["LastPosition"] = lastPosition.ToString();
|
||||
d.Data["LastLookAt"] = lastLookAt.ToString();
|
||||
|
||||
return m_Database.Store(d);
|
||||
bool ret = m_Database.Store(d);
|
||||
if (ret && userID.Length >= 36)
|
||||
cache.Add(userID.Substring(0, 36), d, 300000);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user