From c3d82bdcb1ac2ee0e0bdad75fbf8779252ef31c4 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 8 Jul 2011 22:53:19 +0100 Subject: [PATCH] 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. --- OpenSim/Framework/Util.cs | 16 +++++++++++++--- OpenSim/Services/AssetService/AssetService.cs | 15 ++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 039b926720..fce8999912 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -440,20 +440,30 @@ namespace OpenSim.Framework } /// - /// Return an SHA1 hash of the given string + /// Return an SHA1 hash /// /// /// public static string SHA1Hash(string data) + { + return SHA1Hash(Encoding.Default.GetBytes(data)); + } + + /// + /// Return an SHA1 hash + /// + /// + /// + 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) diff --git a/OpenSim/Services/AssetService/AssetService.cs b/OpenSim/Services/AssetService/AssetService.cs index 851b7b4693..c7a259d2ca 100644 --- a/OpenSim/Services/AssetService/AssetService.cs +++ b/OpenSim/Services/AssetService/AssetService.cs @@ -84,11 +84,20 @@ namespace OpenSim.Services.AssetService if (assetLoaderEnabled) { m_log.InfoFormat("[ASSET]: Loading default asset set from {0}", loaderArgs); - m_AssetLoader.ForEachDefaultXmlAsset(loaderArgs, - delegate(AssetBase a) + + 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); - }); + } + }); } m_log.Info("[ASSET SERVICE]: Local asset service enabled");