don't hold dbconn longer than necessart

httptests
UbitUmarov 2017-05-06 20:40:29 +01:00
parent 76337b1d8e
commit 4b2ef46de6
1 changed files with 31 additions and 21 deletions

View File

@ -131,6 +131,7 @@ namespace OpenSim.Data.MySQL
// m_log.DebugFormat("[MYSQL XASSET DATA]: Looking for asset {0}", assetID); // m_log.DebugFormat("[MYSQL XASSET DATA]: Looking for asset {0}", assetID);
AssetBase asset = null; AssetBase asset = null;
int accessTime = 0;
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{ {
@ -141,7 +142,6 @@ namespace OpenSim.Data.MySQL
dbcon)) dbcon))
{ {
cmd.Parameters.AddWithValue("?ID", assetID.ToString()); cmd.Parameters.AddWithValue("?ID", assetID.ToString());
try try
{ {
using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
@ -160,8 +160,31 @@ namespace OpenSim.Data.MySQL
asset.Temporary = Convert.ToBoolean(dbReader["Temporary"]); asset.Temporary = Convert.ToBoolean(dbReader["Temporary"]);
asset.Flags = (AssetFlags)Convert.ToInt32(dbReader["AssetFlags"]); asset.Flags = (AssetFlags)Convert.ToInt32(dbReader["AssetFlags"]);
accessTime = (int)dbReader["AccessTime"];
}
}
}
catch (Exception e)
{
m_log.Error(string.Format("[MYSQL XASSET DATA]: Failure fetching asset {0}", assetID), e);
}
}
dbcon.Close();
}
if (m_enableCompression) if(asset == null)
return asset;
if(accessTime > 0)
{
try
{
UpdateAccessTime(asset.Metadata, accessTime);
}
catch { }
}
if (m_enableCompression && asset.Data != null)
{ {
using(MemoryStream ms = new MemoryStream(asset.Data)) using(MemoryStream ms = new MemoryStream(asset.Data))
using(GZipStream decompressionStream = new GZipStream(ms, CompressionMode.Decompress)) using(GZipStream decompressionStream = new GZipStream(ms, CompressionMode.Decompress))
@ -177,19 +200,6 @@ namespace OpenSim.Data.MySQL
// asset.ID, asset.Name, asset.Data.Length, compressedLength); // asset.ID, asset.Name, asset.Data.Length, compressedLength);
} }
} }
UpdateAccessTime(asset.Metadata, (int)dbReader["AccessTime"]);
}
}
}
catch (Exception e)
{
m_log.Error(string.Format("[MYSQL XASSET DATA]: Failure fetching asset {0}", assetID), e);
}
}
dbcon.Close();
}
return asset; return asset;
} }