Implement basic gzip compression for xassetdata
Whether this is worthwhile is debatable since here we are not transmitting data over a network In addition, jpeg2000 (the biggest data hog) is already a compressed image format. May not remain.xassetservice
parent
2535a4cafc
commit
75dc8b1aed
|
@ -26,9 +26,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Data;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using log4net;
|
using log4net;
|
||||||
using MySql.Data.MySqlClient;
|
using MySql.Data.MySqlClient;
|
||||||
|
@ -139,6 +141,18 @@ namespace OpenSim.Data.MySQL
|
||||||
|
|
||||||
asset.Temporary = Convert.ToBoolean(dbReader["temporary"]);
|
asset.Temporary = Convert.ToBoolean(dbReader["temporary"]);
|
||||||
asset.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]);
|
asset.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]);
|
||||||
|
|
||||||
|
using (GZipStream decompressionStream = new GZipStream(new MemoryStream(asset.Data), CompressionMode.Decompress))
|
||||||
|
{
|
||||||
|
MemoryStream outputStream = new MemoryStream();
|
||||||
|
WebUtil.CopyTo(decompressionStream, outputStream, int.MaxValue);
|
||||||
|
// int compressedLength = asset.Data.Length;
|
||||||
|
asset.Data = outputStream.ToArray();
|
||||||
|
|
||||||
|
// m_log.DebugFormat(
|
||||||
|
// "[XASSET DB]: Decompressed {0} {1} to {2} bytes from {3}",
|
||||||
|
// asset.ID, asset.Name, asset.Data.Length, compressedLength);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,7 +196,22 @@ namespace OpenSim.Data.MySQL
|
||||||
m_log.Warn("[XASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on add");
|
m_log.Warn("[XASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on add");
|
||||||
}
|
}
|
||||||
|
|
||||||
string hash = Util.SHA1Hash(asset.Data);
|
byte[] compressedData;
|
||||||
|
MemoryStream outputStream = new MemoryStream();
|
||||||
|
|
||||||
|
using (GZipStream compressionStream = new GZipStream(outputStream, CompressionMode.Compress, false))
|
||||||
|
{
|
||||||
|
Console.WriteLine(WebUtil.CopyTo(new MemoryStream(asset.Data), compressionStream, int.MaxValue));
|
||||||
|
// We have to close the compression stream in order to make sure it writes everything out to the underlying memory output stream.
|
||||||
|
compressionStream.Close();
|
||||||
|
compressedData = outputStream.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
string hash = Util.SHA1Hash(compressedData);
|
||||||
|
|
||||||
|
// m_log.DebugFormat(
|
||||||
|
// "[XASSET DB]: Compressed data size for {0} {1}, hash {2} is {3}",
|
||||||
|
// asset.ID, asset.Name, hash, compressedData.Length);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -205,7 +234,6 @@ namespace OpenSim.Data.MySQL
|
||||||
cmd.Parameters.AddWithValue("?access_time", now);
|
cmd.Parameters.AddWithValue("?access_time", now);
|
||||||
cmd.Parameters.AddWithValue("?creator_id", asset.Metadata.CreatorID);
|
cmd.Parameters.AddWithValue("?creator_id", asset.Metadata.CreatorID);
|
||||||
cmd.Parameters.AddWithValue("?asset_flags", (int)asset.Flags);
|
cmd.Parameters.AddWithValue("?asset_flags", (int)asset.Flags);
|
||||||
cmd.Parameters.AddWithValue("?data", asset.Data);
|
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -229,7 +257,7 @@ namespace OpenSim.Data.MySQL
|
||||||
dbcon))
|
dbcon))
|
||||||
{
|
{
|
||||||
cmd.Parameters.AddWithValue("?hash", hash);
|
cmd.Parameters.AddWithValue("?hash", hash);
|
||||||
cmd.Parameters.AddWithValue("?data", asset.Data);
|
cmd.Parameters.AddWithValue("?data", compressedData);
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -422,16 +450,19 @@ namespace OpenSim.Data.MySQL
|
||||||
|
|
||||||
public override bool Delete(string id)
|
public override bool Delete(string id)
|
||||||
{
|
{
|
||||||
|
// m_log.DebugFormat("[XASSETS DB]: Deleting asset {0}", id);
|
||||||
|
|
||||||
lock (m_dbLock)
|
lock (m_dbLock)
|
||||||
{
|
{
|
||||||
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
|
||||||
{
|
{
|
||||||
dbcon.Open();
|
dbcon.Open();
|
||||||
MySqlCommand cmd = new MySqlCommand("delete from xassetsmeta where id=?id", dbcon);
|
|
||||||
|
using (MySqlCommand cmd = new MySqlCommand("delete from xassetsmeta where id=?id", dbcon))
|
||||||
|
{
|
||||||
cmd.Parameters.AddWithValue("?id", id);
|
cmd.Parameters.AddWithValue("?id", id);
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
cmd.Dispose();
|
|
||||||
|
|
||||||
// TODO: How do we deal with data from deleted assets? Probably not easily reapable unless we
|
// TODO: How do we deal with data from deleted assets? Probably not easily reapable unless we
|
||||||
// keep a reference count (?)
|
// keep a reference count (?)
|
||||||
|
|
Loading…
Reference in New Issue