From de44734fe9a0b31cd8cb78c0f58e61a35fe2a259 Mon Sep 17 00:00:00 2001
From: Mic Bowman
Date: Thu, 10 May 2012 09:08:40 -0700
Subject: Saving estate state is really slow (relatively) and it gets
 completely rewritten every time a region starts up. This makes the data write
 only when the data was not already read from the database.

There is a still a major race condition whenever two regions
share the same estate data, but at least it won't be triggered
on startup.
---
 OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs |  5 +++--
 OpenSim/Region/Application/OpenSim.cs                       |  5 +++--
 OpenSim/Region/Application/OpenSimBase.cs                   | 12 +++++++-----
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs b/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs
index 45b8d6f..0065702 100644
--- a/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs
+++ b/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs
@@ -122,9 +122,10 @@ namespace OpenSim.ApplicationPlugins.LoadRegions
                             Thread.CurrentThread.ManagedThreadId.ToString() +
                             ")");
                 
-                m_openSim.PopulateRegionEstateInfo(regionsToLoad[i]);
+                bool changed = m_openSim.PopulateRegionEstateInfo(regionsToLoad[i]);
                 m_openSim.CreateRegion(regionsToLoad[i], true, out scene);
-                regionsToLoad[i].EstateSettings.Save();
+                if (changed)
+		  regionsToLoad[i].EstateSettings.Save();
                 
                 if (scene != null)
                 {
diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs
index 4ec64ee..6796f2b 100644
--- a/OpenSim/Region/Application/OpenSim.cs
+++ b/OpenSim/Region/Application/OpenSim.cs
@@ -618,10 +618,11 @@ namespace OpenSim
                 return;
             }
 
-            PopulateRegionEstateInfo(regInfo);
+            bool changed = PopulateRegionEstateInfo(regInfo);
             IScene scene;
             CreateRegion(regInfo, true, out scene);
-            regInfo.EstateSettings.Save();
+            if (changed)
+	      regInfo.EstateSettings.Save();
         }
 
         /// <summary>
diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs
index 79259d8..045e8d2 100644
--- a/OpenSim/Region/Application/OpenSimBase.cs
+++ b/OpenSim/Region/Application/OpenSimBase.cs
@@ -977,13 +977,13 @@ namespace OpenSim
         /// Load the estate information for the provided RegionInfo object.
         /// </summary>
         /// <param name="regInfo"></param>
-        public void PopulateRegionEstateInfo(RegionInfo regInfo)
+        public bool PopulateRegionEstateInfo(RegionInfo regInfo)
         {
             if (EstateDataService != null)
                 regInfo.EstateSettings = EstateDataService.LoadEstateSettings(regInfo.RegionID, false);
 
             if (regInfo.EstateSettings.EstateID != 0)
-                return;
+                return false;	// estate info in the database did not change
 
             m_log.WarnFormat("[ESTATE] Region {0} is not part of an estate.", regInfo.RegionName);
             
@@ -1018,7 +1018,7 @@ namespace OpenSim
                     }
 
                     if (defaultEstateJoined)
-                        return;
+                        return true; // need to update the database
                     else
                         m_log.ErrorFormat(
                             "[OPENSIM BASE]: Joining default estate {0} failed", defaultEstateName);
@@ -1080,8 +1080,10 @@ namespace OpenSim
                         MainConsole.Instance.Output("Joining the estate failed. Please try again.");
                     }
                 }
-            }
-        }
+	    }
+
+	    return true;	// need to update the database
+	}
     }
     
     public class OpenSimConfigSource
-- 
cgit v1.1