MSSQL patch to mirror mantis 4077 for MySQL to improve region load times

remotes/origin/0.6.7-post-fixes
Chris Hart 2009-09-02 13:28:57 +01:00 committed by Justin Clark-Casey (justincc)
parent 56ddd6828c
commit 4841858600
1 changed files with 38 additions and 24 deletions

View File

@ -97,8 +97,8 @@ namespace OpenSim.Data.MSSQL
{ {
UUID lastGroupID = UUID.Zero; UUID lastGroupID = UUID.Zero;
List<SceneObjectPart> sceneObjectParts = new List<SceneObjectPart>(); Dictionary<UUID, SceneObjectPart> prims = new Dictionary<UUID, SceneObjectPart>();
List<SceneObjectGroup> sceneObjectGroups = new List<SceneObjectGroup>(); Dictionary<UUID, SceneObjectGroup> objects = new Dictionary<UUID, SceneObjectGroup>();
SceneObjectGroup grp = null; SceneObjectGroup grp = null;
@ -123,14 +123,14 @@ namespace OpenSim.Data.MSSQL
else else
sceneObjectPart.Shape = BuildShape(reader); sceneObjectPart.Shape = BuildShape(reader);
sceneObjectParts.Add(sceneObjectPart); prims[sceneObjectPart.UUID] = sceneObjectPart;
UUID groupID = new UUID((Guid)reader["SceneGroupID"]); UUID groupID = new UUID((Guid)reader["SceneGroupID"]);
if (groupID != lastGroupID) // New SOG if (groupID != lastGroupID) // New SOG
{ {
if (grp != null) if (grp != null)
sceneObjectGroups.Add(grp); objects[grp.UUID] = grp;
lastGroupID = groupID; lastGroupID = groupID;
@ -166,37 +166,51 @@ namespace OpenSim.Data.MSSQL
} }
if (grp != null) if (grp != null)
sceneObjectGroups.Add(grp); objects[grp.UUID] = grp;
//Load the inventory off all sceneobjects within the region // Instead of attempting to LoadItems on every prim,
LoadItems(sceneObjectParts); // most of which probably have no items... get a
// list from DB of all prims which have items and
// LoadItems only on those
List<SceneObjectPart> primsWithInventory = new List<SceneObjectPart>();
string qry = "select distinct primID from primitems";
using (AutoClosingSqlCommand command = _Database.Query(qry))
{
using (SqlDataReader itemReader = command.ExecuteReader())
{
while (itemReader.Read())
{
if (!(itemReader["primID"] is DBNull))
{
UUID primID = new UUID(itemReader["primID"].ToString());
if (prims.ContainsKey(primID))
{
primsWithInventory.Add(prims[primID]);
}
}
}
}
}
_Log.DebugFormat("[REGION DB]: Loaded {0} objects using {1} prims", sceneObjectGroups.Count, sceneObjectParts.Count); LoadItems(primsWithInventory);
return sceneObjectGroups; _Log.DebugFormat("[REGION DB]: Loaded {0} objects using {1} prims", objects.Count, prims.Count);
return new List<SceneObjectGroup>(objects.Values);
} }
/// <summary> /// <summary>
/// Load in the prim's persisted inventory. /// Load in the prim's persisted inventory.
/// </summary> /// </summary>
/// <param name="allPrims">all prims on a region</param> /// <param name="allPrims">all prims with inventory on a region</param>
private void LoadItems(List<SceneObjectPart> allPrims) private void LoadItems(List<SceneObjectPart> allPrimsWithInventory)
{ {
using (AutoClosingSqlCommand command = _Database.Query("SELECT * FROM primitems WHERE PrimID = @PrimID")) using (AutoClosingSqlCommand command = _Database.Query("SELECT * FROM primitems WHERE PrimID = @PrimID"))
{ {
bool createParamOnce = true; foreach (SceneObjectPart objectPart in allPrimsWithInventory)
foreach (SceneObjectPart objectPart in allPrims)
{ {
if (createParamOnce) command.Parameters.Add(_Database.CreateParameter("@PrimID", objectPart.UUID));
{
command.Parameters.Add(_Database.CreateParameter("@PrimID", objectPart.UUID));
createParamOnce = false;
}
else
{
command.Parameters["@PrimID"].Value = objectPart.UUID.Guid; //.ToString(); //TODO check if this works
}
List<TaskInventoryItem> inventory = new List<TaskInventoryItem>(); List<TaskInventoryItem> inventory = new List<TaskInventoryItem>();