From 8ef43e5fb3c8596cb793a38f9b5a2611bdb80668 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 7 May 2017 22:22:28 +0100 Subject: take more heavy work out of opened dbconn sections --- OpenSim/Data/MySQL/MySQLSimulationData.cs | 36 +++++++++++++++++++------------ 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'OpenSim/Data/MySQL/MySQLSimulationData.cs') diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs index 4766372..e754522 100644 --- a/OpenSim/Data/MySQL/MySQLSimulationData.cs +++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs @@ -607,6 +607,10 @@ namespace OpenSim.Data.MySQL { m_log.Info("[REGION DB]: Storing terrain"); + int terrainDBRevision; + Array terrainDBblob; + terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob); + lock (m_dbLock) { using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) @@ -626,10 +630,6 @@ namespace OpenSim.Data.MySQL "Revision, Heightfield) values (?RegionUUID, " + "?Revision, ?Heightfield)"; - int terrainDBRevision; - Array terrainDBblob; - terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob); - cmd2.Parameters.AddWithValue("RegionUUID", regionID.ToString()); cmd2.Parameters.AddWithValue("Revision", terrainDBRevision); cmd2.Parameters.AddWithValue("Heightfield", terrainDBblob); @@ -655,6 +655,10 @@ namespace OpenSim.Data.MySQL { m_log.Info("[REGION DB]: Storing Baked terrain"); + int terrainDBRevision; + Array terrainDBblob; + terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob); + lock (m_dbLock) { using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) @@ -674,10 +678,6 @@ namespace OpenSim.Data.MySQL "Revision, Heightfield) values (?RegionUUID, " + "?Revision, ?Heightfield)"; - int terrainDBRevision; - Array terrainDBblob; - terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob); - cmd2.Parameters.AddWithValue("RegionUUID", regionID.ToString()); cmd2.Parameters.AddWithValue("Revision", terrainDBRevision); cmd2.Parameters.AddWithValue("Heightfield", terrainDBblob); @@ -711,9 +711,12 @@ namespace OpenSim.Data.MySQL public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ) { TerrainData terrData = null; + byte[] blob = null; + int rev = 0; lock (m_dbLock) { + using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) { dbcon.Open(); @@ -729,11 +732,10 @@ namespace OpenSim.Data.MySQL { while (reader.Read()) { - int rev = Convert.ToInt32(reader["Revision"]); + rev = Convert.ToInt32(reader["Revision"]); if ((reader["Heightfield"] != DBNull.Value)) { - byte[] blob = (byte[])reader["Heightfield"]; - terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob); + blob = (byte[])reader["Heightfield"]; } } } @@ -742,12 +744,17 @@ namespace OpenSim.Data.MySQL } } + if(blob != null) + terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob); + return terrData; } public TerrainData LoadBakedTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ) { TerrainData terrData = null; + byte[] blob = null; + int rev = 0; lock (m_dbLock) { @@ -765,11 +772,10 @@ namespace OpenSim.Data.MySQL { while (reader.Read()) { - int rev = Convert.ToInt32(reader["Revision"]); + rev = Convert.ToInt32(reader["Revision"]); if ((reader["Heightfield"] != DBNull.Value)) { - byte[] blob = (byte[])reader["Heightfield"]; - terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob); + blob = (byte[])reader["Heightfield"]; } } } @@ -777,6 +783,8 @@ namespace OpenSim.Data.MySQL dbcon.Close(); } } + if(blob != null) + terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob); return terrData; } -- cgit v1.1