When loading library asset set, only store an asset if it's different from an existing one with the same id.
We compare existing and loaded asset by doing an SHA1 on both, so that a changed library asset will still update the store. This cuts asset library load time from 10 seconds to <1 sec. Note, a fix on the previous commit revealed a bug where a library script cannot be copied except on the first login after a cache clear. This is unrelated to this commit and needs to be fixed at some subsequent time.bulletsim
parent
a048ec3f95
commit
c3d82bdcb1
|
@ -440,20 +440,30 @@ namespace OpenSim.Framework
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return an SHA1 hash of the given string
|
||||
/// Return an SHA1 hash
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public static string SHA1Hash(string data)
|
||||
{
|
||||
return SHA1Hash(Encoding.Default.GetBytes(data));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return an SHA1 hash
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public static string SHA1Hash(byte[] data)
|
||||
{
|
||||
byte[] hash = ComputeSHA1Hash(data);
|
||||
return BitConverter.ToString(hash).Replace("-", String.Empty);
|
||||
}
|
||||
|
||||
private static byte[] ComputeSHA1Hash(string src)
|
||||
private static byte[] ComputeSHA1Hash(byte[] src)
|
||||
{
|
||||
SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider();
|
||||
return SHA1.ComputeHash(Encoding.Default.GetBytes(src));
|
||||
return SHA1.ComputeHash(src);
|
||||
}
|
||||
|
||||
public static int fast_distance2d(int x, int y)
|
||||
|
|
|
@ -84,10 +84,19 @@ namespace OpenSim.Services.AssetService
|
|||
if (assetLoaderEnabled)
|
||||
{
|
||||
m_log.InfoFormat("[ASSET]: Loading default asset set from {0}", loaderArgs);
|
||||
m_AssetLoader.ForEachDefaultXmlAsset(loaderArgs,
|
||||
|
||||
m_AssetLoader.ForEachDefaultXmlAsset(
|
||||
loaderArgs,
|
||||
delegate(AssetBase a)
|
||||
{
|
||||
AssetBase existingAsset = Get(a.ID);
|
||||
// AssetMetadata existingMetadata = GetMetadata(a.ID);
|
||||
|
||||
if (existingAsset == null || Util.SHA1Hash(existingAsset.Data) != Util.SHA1Hash(a.Data))
|
||||
{
|
||||
// m_log.DebugFormat("[ASSET]: Storing {0} {1}", a.Name, a.ID);
|
||||
Store(a);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue