If asset data already exists with the required hash then don't rewrite it
parent
94b323d1d8
commit
2535a4cafc
|
@ -168,7 +168,6 @@ namespace OpenSim.Data.MySQL
|
||||||
|
|
||||||
using (MySqlTransaction transaction = dbcon.BeginTransaction())
|
using (MySqlTransaction transaction = dbcon.BeginTransaction())
|
||||||
{
|
{
|
||||||
|
|
||||||
string assetName = asset.Name;
|
string assetName = asset.Name;
|
||||||
if (asset.Name.Length > 64)
|
if (asset.Name.Length > 64)
|
||||||
{
|
{
|
||||||
|
@ -220,26 +219,29 @@ namespace OpenSim.Data.MySQL
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
if (!ExistsData(dbcon, transaction, hash))
|
||||||
{
|
{
|
||||||
using (MySqlCommand cmd =
|
try
|
||||||
new MySqlCommand(
|
|
||||||
"replace INTO xassetsdata(hash, data) VALUES(?hash, ?data)",
|
|
||||||
dbcon))
|
|
||||||
{
|
{
|
||||||
cmd.Parameters.AddWithValue("?hash", hash);
|
using (MySqlCommand cmd =
|
||||||
cmd.Parameters.AddWithValue("?data", asset.Data);
|
new MySqlCommand(
|
||||||
cmd.ExecuteNonQuery();
|
"INSERT INTO xassetsdata(hash, data) VALUES(?hash, ?data)",
|
||||||
|
dbcon))
|
||||||
|
{
|
||||||
|
cmd.Parameters.AddWithValue("?hash", hash);
|
||||||
|
cmd.Parameters.AddWithValue("?data", asset.Data);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
catch (Exception e)
|
||||||
catch (Exception e)
|
{
|
||||||
{
|
m_log.ErrorFormat("[XASSET DB]: MySQL failure creating asset data {0} with name \"{1}\". Error: {2}",
|
||||||
m_log.ErrorFormat("[XASSET DB]: MySQL failure creating asset data {0} with name \"{1}\". Error: {2}",
|
asset.FullID, asset.Name, e.Message);
|
||||||
asset.FullID, asset.Name, e.Message);
|
|
||||||
|
|
||||||
transaction.Rollback();
|
transaction.Rollback();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
|
@ -284,6 +286,46 @@ namespace OpenSim.Data.MySQL
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// We assume we already have the m_dbLock.
|
||||||
|
/// </summary>
|
||||||
|
/// TODO: need to actually use the transaction.
|
||||||
|
/// <param name="dbcon"></param>
|
||||||
|
/// <param name="transaction"></param>
|
||||||
|
/// <param name="hash"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private bool ExistsData(MySqlConnection dbcon, MySqlTransaction transaction, string hash)
|
||||||
|
{
|
||||||
|
// m_log.DebugFormat("[ASSETS DB]: Checking for asset {0}", uuid);
|
||||||
|
|
||||||
|
bool exists = false;
|
||||||
|
|
||||||
|
using (MySqlCommand cmd = new MySqlCommand("SELECT hash FROM xassetsdata WHERE hash=?hash", dbcon))
|
||||||
|
{
|
||||||
|
cmd.Parameters.AddWithValue("?hash", hash);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
|
||||||
|
{
|
||||||
|
if (dbReader.Read())
|
||||||
|
{
|
||||||
|
// m_log.DebugFormat("[ASSETS DB]: Found asset {0}", uuid);
|
||||||
|
exists = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
m_log.ErrorFormat(
|
||||||
|
"[XASSETS DB]: MySql failure in ExistsData fetching hash {0}. Exception {1}{2}",
|
||||||
|
hash, e.Message, e.StackTrace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return exists;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if the asset exists in the database
|
/// Check if the asset exists in the database
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue