diff options
author | Justin Clark-Casey (justincc) | 2012-03-03 01:43:36 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-03-03 01:43:36 +0000 |
commit | 3780df8a329c81471c486acab7f641f7742267f4 (patch) | |
tree | e36efba7a25e305d5f9d381b18af8a1b9dac96b0 | |
parent | Implement basic gzip compression for xassetdata (diff) | |
download | opensim-SC-3780df8a329c81471c486acab7f641f7742267f4.zip opensim-SC-3780df8a329c81471c486acab7f641f7742267f4.tar.gz opensim-SC-3780df8a329c81471c486acab7f641f7742267f4.tar.bz2 opensim-SC-3780df8a329c81471c486acab7f641f7742267f4.tar.xz |
Make asset compression optional. Currently set to false and not configurable from outside MySQLXAssetData.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/MySQL/MySQLXAssetData.cs | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/OpenSim/Data/MySQL/MySQLXAssetData.cs b/OpenSim/Data/MySQL/MySQLXAssetData.cs index bb03871..bfc1c55 100644 --- a/OpenSim/Data/MySQL/MySQLXAssetData.cs +++ b/OpenSim/Data/MySQL/MySQLXAssetData.cs | |||
@@ -44,6 +44,7 @@ namespace OpenSim.Data.MySQL | |||
44 | { | 44 | { |
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
46 | 46 | ||
47 | private bool m_enableCompression = false; | ||
47 | private string m_connectionString; | 48 | private string m_connectionString; |
48 | private object m_dbLock = new object(); | 49 | private object m_dbLock = new object(); |
49 | 50 | ||
@@ -142,16 +143,19 @@ namespace OpenSim.Data.MySQL | |||
142 | asset.Temporary = Convert.ToBoolean(dbReader["temporary"]); | 143 | asset.Temporary = Convert.ToBoolean(dbReader["temporary"]); |
143 | asset.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]); | 144 | asset.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]); |
144 | 145 | ||
145 | using (GZipStream decompressionStream = new GZipStream(new MemoryStream(asset.Data), CompressionMode.Decompress)) | 146 | if (m_enableCompression) |
146 | { | 147 | { |
147 | MemoryStream outputStream = new MemoryStream(); | 148 | using (GZipStream decompressionStream = new GZipStream(new MemoryStream(asset.Data), CompressionMode.Decompress)) |
148 | WebUtil.CopyTo(decompressionStream, outputStream, int.MaxValue); | 149 | { |
149 | // int compressedLength = asset.Data.Length; | 150 | MemoryStream outputStream = new MemoryStream(); |
150 | asset.Data = outputStream.ToArray(); | 151 | WebUtil.CopyTo(decompressionStream, outputStream, int.MaxValue); |
151 | 152 | // int compressedLength = asset.Data.Length; | |
152 | // m_log.DebugFormat( | 153 | asset.Data = outputStream.ToArray(); |
153 | // "[XASSET DB]: Decompressed {0} {1} to {2} bytes from {3}", | 154 | |
154 | // asset.ID, asset.Name, asset.Data.Length, compressedLength); | 155 | // m_log.DebugFormat( |
156 | // "[XASSET DB]: Decompressed {0} {1} to {2} bytes from {3}", | ||
157 | // asset.ID, asset.Name, asset.Data.Length, compressedLength); | ||
158 | } | ||
155 | } | 159 | } |
156 | } | 160 | } |
157 | } | 161 | } |
@@ -199,15 +203,19 @@ namespace OpenSim.Data.MySQL | |||
199 | byte[] compressedData; | 203 | byte[] compressedData; |
200 | MemoryStream outputStream = new MemoryStream(); | 204 | MemoryStream outputStream = new MemoryStream(); |
201 | 205 | ||
202 | using (GZipStream compressionStream = new GZipStream(outputStream, CompressionMode.Compress, false)) | 206 | if (m_enableCompression) |
203 | { | 207 | { |
204 | Console.WriteLine(WebUtil.CopyTo(new MemoryStream(asset.Data), compressionStream, int.MaxValue)); | 208 | using (GZipStream compressionStream = new GZipStream(outputStream, CompressionMode.Compress, false)) |
205 | // We have to close the compression stream in order to make sure it writes everything out to the underlying memory output stream. | 209 | { |
206 | compressionStream.Close(); | 210 | // Console.WriteLine(WebUtil.CopyTo(new MemoryStream(asset.Data), compressionStream, int.MaxValue)); |
207 | compressedData = outputStream.ToArray(); | 211 | // We have to close the compression stream in order to make sure it writes everything out to the underlying memory output stream. |
212 | compressionStream.Close(); | ||
213 | compressedData = outputStream.ToArray(); | ||
214 | asset.Data = compressedData; | ||
215 | } | ||
208 | } | 216 | } |
209 | 217 | ||
210 | string hash = Util.SHA1Hash(compressedData); | 218 | string hash = Util.SHA1Hash(asset.Data); |
211 | 219 | ||
212 | // m_log.DebugFormat( | 220 | // m_log.DebugFormat( |
213 | // "[XASSET DB]: Compressed data size for {0} {1}, hash {2} is {3}", | 221 | // "[XASSET DB]: Compressed data size for {0} {1}, hash {2} is {3}", |
@@ -257,7 +265,7 @@ namespace OpenSim.Data.MySQL | |||
257 | dbcon)) | 265 | dbcon)) |
258 | { | 266 | { |
259 | cmd.Parameters.AddWithValue("?hash", hash); | 267 | cmd.Parameters.AddWithValue("?hash", hash); |
260 | cmd.Parameters.AddWithValue("?data", compressedData); | 268 | cmd.Parameters.AddWithValue("?data", asset.Data); |
261 | cmd.ExecuteNonQuery(); | 269 | cmd.ExecuteNonQuery(); |
262 | } | 270 | } |
263 | } | 271 | } |