diff options
author | Chris Hart | 2009-09-02 13:28:57 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2009-09-02 19:42:18 +0100 |
commit | 4841858600cf35903966d48451015b2be5e97d5c (patch) | |
tree | 7a6ceb7f537652b224441bc0f08afe3a0a05a128 | |
parent | Add copyright headers. Formatting cleanup. (diff) | |
download | opensim-SC-4841858600cf35903966d48451015b2be5e97d5c.zip opensim-SC-4841858600cf35903966d48451015b2be5e97d5c.tar.gz opensim-SC-4841858600cf35903966d48451015b2be5e97d5c.tar.bz2 opensim-SC-4841858600cf35903966d48451015b2be5e97d5c.tar.xz |
MSSQL patch to mirror mantis 4077 for MySQL to improve region load times
-rw-r--r-- | OpenSim/Data/MSSQL/MSSQLRegionData.cs | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLRegionData.cs b/OpenSim/Data/MSSQL/MSSQLRegionData.cs index d79d32b..c9e4bfe 100644 --- a/OpenSim/Data/MSSQL/MSSQLRegionData.cs +++ b/OpenSim/Data/MSSQL/MSSQLRegionData.cs | |||
@@ -97,8 +97,8 @@ namespace OpenSim.Data.MSSQL | |||
97 | { | 97 | { |
98 | UUID lastGroupID = UUID.Zero; | 98 | UUID lastGroupID = UUID.Zero; |
99 | 99 | ||
100 | List<SceneObjectPart> sceneObjectParts = new List<SceneObjectPart>(); | 100 | Dictionary<UUID, SceneObjectPart> prims = new Dictionary<UUID, SceneObjectPart>(); |
101 | List<SceneObjectGroup> sceneObjectGroups = new List<SceneObjectGroup>(); | 101 | Dictionary<UUID, SceneObjectGroup> objects = new Dictionary<UUID, SceneObjectGroup>(); |
102 | SceneObjectGroup grp = null; | 102 | SceneObjectGroup grp = null; |
103 | 103 | ||
104 | 104 | ||
@@ -123,14 +123,14 @@ namespace OpenSim.Data.MSSQL | |||
123 | else | 123 | else |
124 | sceneObjectPart.Shape = BuildShape(reader); | 124 | sceneObjectPart.Shape = BuildShape(reader); |
125 | 125 | ||
126 | sceneObjectParts.Add(sceneObjectPart); | 126 | prims[sceneObjectPart.UUID] = sceneObjectPart; |
127 | 127 | ||
128 | UUID groupID = new UUID((Guid)reader["SceneGroupID"]); | 128 | UUID groupID = new UUID((Guid)reader["SceneGroupID"]); |
129 | 129 | ||
130 | if (groupID != lastGroupID) // New SOG | 130 | if (groupID != lastGroupID) // New SOG |
131 | { | 131 | { |
132 | if (grp != null) | 132 | if (grp != null) |
133 | sceneObjectGroups.Add(grp); | 133 | objects[grp.UUID] = grp; |
134 | 134 | ||
135 | lastGroupID = groupID; | 135 | lastGroupID = groupID; |
136 | 136 | ||
@@ -166,38 +166,52 @@ namespace OpenSim.Data.MSSQL | |||
166 | } | 166 | } |
167 | 167 | ||
168 | if (grp != null) | 168 | if (grp != null) |
169 | sceneObjectGroups.Add(grp); | 169 | objects[grp.UUID] = grp; |
170 | |||
171 | // Instead of attempting to LoadItems on every prim, | ||
172 | // most of which probably have no items... get a | ||
173 | // list from DB of all prims which have items and | ||
174 | // LoadItems only on those | ||
175 | List<SceneObjectPart> primsWithInventory = new List<SceneObjectPart>(); | ||
176 | string qry = "select distinct primID from primitems"; | ||
177 | using (AutoClosingSqlCommand command = _Database.Query(qry)) | ||
178 | { | ||
179 | using (SqlDataReader itemReader = command.ExecuteReader()) | ||
180 | { | ||
181 | while (itemReader.Read()) | ||
182 | { | ||
183 | if (!(itemReader["primID"] is DBNull)) | ||
184 | { | ||
185 | UUID primID = new UUID(itemReader["primID"].ToString()); | ||
186 | if (prims.ContainsKey(primID)) | ||
187 | { | ||
188 | primsWithInventory.Add(prims[primID]); | ||
189 | } | ||
190 | } | ||
191 | } | ||
192 | } | ||
193 | } | ||
170 | 194 | ||
171 | //Load the inventory off all sceneobjects within the region | 195 | LoadItems(primsWithInventory); |
172 | LoadItems(sceneObjectParts); | ||
173 | 196 | ||
174 | _Log.DebugFormat("[REGION DB]: Loaded {0} objects using {1} prims", sceneObjectGroups.Count, sceneObjectParts.Count); | 197 | _Log.DebugFormat("[REGION DB]: Loaded {0} objects using {1} prims", objects.Count, prims.Count); |
175 | 198 | ||
176 | return sceneObjectGroups; | 199 | return new List<SceneObjectGroup>(objects.Values); |
177 | } | 200 | } |
178 | 201 | ||
179 | /// <summary> | 202 | /// <summary> |
180 | /// Load in the prim's persisted inventory. | 203 | /// Load in the prim's persisted inventory. |
181 | /// </summary> | 204 | /// </summary> |
182 | /// <param name="allPrims">all prims on a region</param> | 205 | /// <param name="allPrims">all prims with inventory on a region</param> |
183 | private void LoadItems(List<SceneObjectPart> allPrims) | 206 | private void LoadItems(List<SceneObjectPart> allPrimsWithInventory) |
184 | { | 207 | { |
208 | |||
185 | using (AutoClosingSqlCommand command = _Database.Query("SELECT * FROM primitems WHERE PrimID = @PrimID")) | 209 | using (AutoClosingSqlCommand command = _Database.Query("SELECT * FROM primitems WHERE PrimID = @PrimID")) |
186 | { | 210 | { |
187 | bool createParamOnce = true; | 211 | foreach (SceneObjectPart objectPart in allPrimsWithInventory) |
188 | |||
189 | foreach (SceneObjectPart objectPart in allPrims) | ||
190 | { | 212 | { |
191 | if (createParamOnce) | 213 | command.Parameters.Add(_Database.CreateParameter("@PrimID", objectPart.UUID)); |
192 | { | 214 | |
193 | command.Parameters.Add(_Database.CreateParameter("@PrimID", objectPart.UUID)); | ||
194 | createParamOnce = false; | ||
195 | } | ||
196 | else | ||
197 | { | ||
198 | command.Parameters["@PrimID"].Value = objectPart.UUID.Guid; //.ToString(); //TODO check if this works | ||
199 | } | ||
200 | |||
201 | List<TaskInventoryItem> inventory = new List<TaskInventoryItem>(); | 215 | List<TaskInventoryItem> inventory = new List<TaskInventoryItem>(); |
202 | 216 | ||
203 | using (SqlDataReader reader = command.ExecuteReader()) | 217 | using (SqlDataReader reader = command.ExecuteReader()) |