From a260466147b47de1d51539b5c23429440d94124f Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Mon, 8 Dec 2008 16:29:48 +0000 Subject: fix an issue I found where primshapes weren't every being removed because of a logic error. attempt to speed up deletes a bit by batching up all the primitem deletes and primshape deletes into single delete statements. This removes the lock/release/lock/release/lock/release for loop. --- OpenSim/Data/MySQL/MySQLRegionData.cs | 91 +++++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 9 deletions(-) (limited to 'OpenSim/Data/MySQL') diff --git a/OpenSim/Data/MySQL/MySQLRegionData.cs b/OpenSim/Data/MySQL/MySQLRegionData.cs index 8c49531..4dc0685 100644 --- a/OpenSim/Data/MySQL/MySQLRegionData.cs +++ b/OpenSim/Data/MySQL/MySQLRegionData.cs @@ -300,20 +300,22 @@ namespace OpenSim.Data.MySQL reader.Close(); } - foreach (UUID uuid in uuids) - RemoveItems(uuid); - + // delete the main prims cmd.CommandText = "delete from prims where SceneGroupID= ?UUID"; - - ExecuteNonQuery(cmd); - - cmd.CommandText = "delete from primshapes where UUID = ?UUID"; - ExecuteNonQuery(cmd); cmd.Dispose(); + + // there is no way this should be < 1 unless there is + // a very corrupt database, but in that case be extra + // safe anyway. + if (uuids.Count > 0) + { + RemoveShapes(uuids); + RemoveItems(uuids); + } } } - + /// /// Remove all persisted items of the given prim. /// The caller must acquire the necessrary synchronization locks @@ -335,6 +337,77 @@ namespace OpenSim.Data.MySQL } } + + /// + /// Remove all persisted shapes for a list of prims + /// The caller must acquire the necessrary synchronization locks + /// + /// the list of UUIDs + private void RemoveShapes(List uuids) + { + lock (m_Connection) + { + string sql = "delete from primshapes where "; + MySqlCommand cmd = m_Connection.CreateCommand(); + + for (int i = 0; i < uuids.Count; i++) + { + if ((i + 1) == uuids.Count) + {// end of the list + sql += "(UUID = ?UUID" + i + ")"; + } + else + { + sql += "(UUID = ?UUID" + i + ") or "; + } + } + cmd.CommandText = sql; + + for (int i = 0; i < uuids.Count; i++) + { + cmd.Parameters.AddWithValue("UUID" + i, uuids[i].ToString()); + } + + ExecuteNonQuery(cmd); + cmd.Dispose(); + } + } + + /// + /// Remove all persisted items for a list of prims + /// The caller must acquire the necessrary synchronization locks + /// + /// the list of UUIDs + private void RemoveItems(List uuids) + { + lock (m_Connection) + { + string sql = "delete from primitems where "; + MySqlCommand cmd = m_Connection.CreateCommand(); + + for (int i = 0; i < uuids.Count; i++) + { + if ((i + 1) == uuids.Count) + {// end of the list + sql += "(PrimID = ?PrimID" + i + ")"; + } + else + { + sql += "(PrimID = ?PrimID" + i + ") or "; + } + } + cmd.CommandText = sql; + + for (int i = 0; i < uuids.Count; i++) + { + cmd.Parameters.AddWithValue("PrimID" + i, uuids[i].ToString()); + } + + ExecuteNonQuery(cmd); + cmd.Dispose(); + } + } + public List LoadObjects(UUID regionUUID) { UUID lastGroupID = UUID.Zero; -- cgit v1.1