Explorar el Código

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

UbitUmarov hace 3 años
padre
commit
2f66a82cbe
Se han modificado 1 ficheros con 60 adiciones y 24 borrados
  1. 60 24
      OpenSim/Services/UserAccountService/GridUserService.cs

+ 60 - 24
OpenSim/Services/UserAccountService/GridUserService.cs

@@ -126,38 +126,54 @@ namespace OpenSim.Services.UserAccountService
             MainConsole.Instance.Output("Users online: {0}", onlineRecentlyCount);
             MainConsole.Instance.Output("Users online: {0}", onlineRecentlyCount);
         }
         }
 
 
+        private static ExpiringCacheOS<string, GridUserData> cache = new ExpiringCacheOS<string, GridUserData>(00000);
         private GridUserData GetGridUserData(string userID)
         private GridUserData GetGridUserData(string userID)
         {
         {
-            GridUserData d = null;
-            if (userID.Length > 36) // it's a UUI
+            if (userID.Length > 36)
+                userID = userID.Substring(0, 36);
+
+            if (cache.TryGetValue(userID, out GridUserData d))
+               return d;
+
+            GridUserData[] ds = m_Database.GetAll(userID);
+            if (ds == null || ds.Length == 0)
             {
             {
-                d = m_Database.Get(userID);
+                cache.Add(userID, null, 300000);
+                return null;
             }
             }
-            else // it's a UUID
-            {
-                GridUserData[] ds = m_Database.GetAll(userID);
-                if (ds == null)
-                    return null;
 
 
-                if (ds.Length > 0)
+            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
+                    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;
                             d = dd;
+                        }
+                    }
                 }
                 }
+                catch { }
             }
             }
-
+            cache.Add(userID, d, 300000);
             return d;
             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();
             GridUserInfo info = new GridUserInfo();
             info.UserID = d.UserID;
             info.UserID = d.UserID;
             info.HomeRegionID = new UUID(d.Data["HomeRegionID"]);
             info.HomeRegionID = new UUID(d.Data["HomeRegionID"]);
@@ -171,10 +187,19 @@ namespace OpenSim.Services.UserAccountService
             info.Online = bool.Parse(d.Data["Online"]);
             info.Online = bool.Parse(d.Data["Online"]);
             info.Login = Util.ToDateTime(Convert.ToInt32(d.Data["Login"]));
             info.Login = Util.ToDateTime(Convert.ToInt32(d.Data["Login"]));
             info.Logout = Util.ToDateTime(Convert.ToInt32(d.Data["Logout"]));
             info.Logout = Util.ToDateTime(Convert.ToInt32(d.Data["Logout"]));
-
             return info;
             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)
         public virtual GridUserInfo[] GetGridUserInfo(string[] userIDs)
         {
         {
             List<GridUserInfo> ret = new List<GridUserInfo>();
             List<GridUserInfo> ret = new List<GridUserInfo>();
@@ -201,8 +226,10 @@ namespace OpenSim.Services.UserAccountService
             d.Data["Login"] = Util.UnixTimeSinceEpoch().ToString();
             d.Data["Login"] = Util.UnixTimeSinceEpoch().ToString();
 
 
             m_Database.Store(d);
             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)
         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["LastPosition"] = lastPosition.ToString();
             d.Data["LastLookAt"] = lastLookAt.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)
         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["HomePosition"] = homePosition.ToString();
             d.Data["HomeLookAt"] = homeLookAt.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)
         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["LastPosition"] = lastPosition.ToString();
             d.Data["LastLookAt"] = lastLookAt.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;
         }
         }
     }
     }
 }
 }