Browse Source

in some cases store a hg asset on local grid is just waste

UbitUmarov 3 years ago
parent
commit
7b106564fa

+ 4 - 20
OpenSim/Capabilities/Handlers/GetAssets/GetAssetsHandler.cs

@@ -121,29 +121,13 @@ namespace OpenSim.Capabilities.Handlers
             if(!UUID.TryParse(assetStr, out assetID))
                 return;
 
-            AssetBase asset = m_assetService.Get(assetID.ToString());
-            if (asset == null)
+            AssetBase asset = m_assetService.Get(assetID.ToString(), serviceURL, false);
+            if (asset == null || asset.Type != (sbyte)type)
             {
-                if (String.IsNullOrWhiteSpace(serviceURL))
-                {
-                    // m_log.Warn("[GETASSET]: not found: " + query + " " + assetStr);
-                    response.StatusCode = (int)HttpStatusCode.NotFound;
-                    return;
-                }
-
-                string newid = serviceURL + "/" + assetID.ToString();
-                asset = m_assetService.Get(newid);
-                if (asset == null)
-                {
-                    // m_log.Warn("[GETASSET]: not found: " + query + " " + assetStr);
-                    response.StatusCode = (int)HttpStatusCode.NotFound;
-                    return;
-                }
                 // m_log.Warn("[GETASSET]: not found: " + query + " " + assetStr);
-            }
-
-            if (asset.Type != (sbyte)type)
+                response.StatusCode = (int)HttpStatusCode.NotFound;
                 return;
+            }
 
             int len = asset.Data.Length;
 

+ 44 - 2
OpenSim/Region/CoreModules/Asset/FlotsamAssetCache.cs

@@ -562,7 +562,7 @@ namespace OpenSim.Region.CoreModules.Asset
             return asset;
         }
 
-        public AssetBase Get(string id, string ForeignAssetService)
+        public AssetBase Get(string id, string ForeignAssetService, bool dummy)
         {
             return null;
         }
@@ -630,9 +630,51 @@ namespace OpenSim.Region.CoreModules.Asset
             return false;
         }
 
+        // does not check negative cache
         public AssetBase GetCached(string id)
         {
-            Get(id, out AssetBase asset);
+            AssetBase asset = null;
+
+            m_Requests++;
+
+            asset = GetFromWeakReference(id);
+            if (asset != null)
+            {
+                if (m_updateFileTimeOnCacheHit)
+                {
+                    string filename = GetFileName(id);
+                    UpdateFileLastAccessTime(filename);
+                }
+                if (m_MemoryCacheEnabled)
+                    UpdateMemoryCache(id, asset);
+                return asset;
+            }
+
+            if (m_MemoryCacheEnabled)
+            {
+                asset = GetFromMemoryCache(id);
+                if (asset != null)
+                {
+                    UpdateWeakReference(id, asset);
+                    if (m_updateFileTimeOnCacheHit)
+                    {
+                        string filename = GetFileName(id);
+                        UpdateFileLastAccessTime(filename);
+                    }
+                    return asset;
+                }
+            }
+
+            if (m_FileCacheEnabled)
+            {
+                asset = GetFromFileCache(id);
+                if (asset != null)
+                {
+                    UpdateWeakReference(id, asset);
+                    if (m_MemoryCacheEnabled)
+                        UpdateMemoryCache(id, asset);
+                }
+            }
             return asset;
         }
 

+ 1 - 1
OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs

@@ -1891,7 +1891,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
             if(string.IsNullOrWhiteSpace(assetServerURI))
                 return;
 
-            Scene.AssetService.Get(imageID.ToString(), assetServerURI);
+            Scene.AssetService.Get(imageID.ToString(), assetServerURI, false);
         }
 
         /// <summary>

+ 1 - 18
OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs

@@ -90,24 +90,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
 
         private AssetBase FetchAsset(string url, UUID assetID)
         {
-            string assetIDstr = assetID.ToString();
-            // Test if it's already here
-            AssetBase asset = m_scene.AssetService.Get(assetIDstr);
-            if (asset == null)
-            {
-                if (string.IsNullOrEmpty(url))
-                    return null;
-
-                asset = m_scene.AssetService.Get(assetIDstr, url);
-
-                //if (asset != null)
-                //    m_log.DebugFormat("[HG ASSET MAPPER]: Fetched asset {0} of type {1} from {2} ", assetID, asset.Metadata.Type, url);
-                //else
-                //    m_log.DebugFormat("[HG ASSET MAPPER]: Unable to fetch asset {0} from {1} ", assetID, url);
-
-            }
-
-            return asset;
+            return m_scene.AssetService.Get(url, assetID.ToString(), true);
         }
 
         public bool PostAsset(string url, AssetBase asset, bool verbose = true)

+ 2 - 2
OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs

@@ -166,7 +166,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
             return asset;
         }
 
-        public AssetBase Get(string id, string ForeignAssetService)
+        public AssetBase Get(string id, string ForeignAssetService, bool dummy)
         {
             return null;
         }
@@ -231,7 +231,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
             return null;
         }
 
-        public bool Get(string id, Object sender, AssetRetrieved handler)
+        public bool Get(string id, object sender, AssetRetrieved handler)
         {
 //            m_log.DebugFormat("[LOCAL ASSET SERVICES CONNECTOR]: Asynchronously requesting asset {0}", id);
 

+ 6 - 3
OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/RegionAssetConnectorModule.cs

@@ -229,7 +229,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
         {
             if (m_HGConnector == null || string.IsNullOrEmpty(ForeignAssetService))
                 return null;
-            return m_HGConnector.Get(id , ForeignAssetService);
+            return m_HGConnector.Get(id , ForeignAssetService, true);
         }
 
         public AssetBase GetForeign(string id)
@@ -288,7 +288,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
             return asset;
         }
 
-        public AssetBase Get(string id, string ForeignAssetService)
+        public AssetBase Get(string id, string ForeignAssetService, bool StoreOnLocalGrid)
         {
             // assumes id and ForeignAssetService are valid and resolved
             AssetBase asset = null;
@@ -311,7 +311,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
                             m_Cache.CacheNegative(id);
                         return null;
                     }
-                    Store(asset);
+                    if(StoreOnLocalGrid)
+                        Store(asset);
+                    else if (m_Cache != null)
+                        m_Cache.Cache(asset);
                 }
                 else if (m_Cache != null)
                     m_Cache.CacheNegative(id);

+ 1 - 1
OpenSim/Services/AssetService/AssetService.cs

@@ -113,7 +113,7 @@ namespace OpenSim.Services.AssetService
             }
         }
 
-        public AssetBase Get(string id, string ForeignAssetService)
+        public AssetBase Get(string id, string ForeignAssetService, bool dummy)
         {
             return null;
         }

+ 1 - 1
OpenSim/Services/AssetService/XAssetService.cs

@@ -129,7 +129,7 @@ namespace OpenSim.Services.AssetService
             }
         }
 
-        public AssetBase Get(string id, string ForeignAssetService)
+        public AssetBase Get(string id, string ForeignAssetService, bool dummy)
         {
             return null;
         }

+ 1 - 1
OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs

@@ -156,7 +156,7 @@ namespace OpenSim.Services.Connectors
             return asset;
         }
 
-        public AssetBase Get(string id, string ForeignAssetService)
+        public AssetBase Get(string id, string ForeignAssetService, bool dummy)
         {
             return null;
         }

+ 1 - 1
OpenSim/Services/Connectors/Asset/HGAssetServiceConnector.cs

@@ -85,7 +85,7 @@ namespace OpenSim.Services.Connectors
             return null;
         }
 
-        public AssetBase Get(string id, string ForeignAssetService)
+        public AssetBase Get(string id, string ForeignAssetService, bool dummy)
         {
             IAssetService connector = GetConnector(ForeignAssetService);
             return connector.Get(id);

+ 1 - 1
OpenSim/Services/FSAssetService/FSAssetService.cs

@@ -420,7 +420,7 @@ namespace OpenSim.Services.FSAssetService
             return Get(id, out hash);
         }
 
-        public AssetBase Get(string id, string ForeignAssetService)
+        public AssetBase Get(string id, string ForeignAssetService, bool dummy)
         {
             return null;
         }

+ 1 - 1
OpenSim/Services/HypergridService/HGAssetService.cs

@@ -125,7 +125,7 @@ namespace OpenSim.Services.HypergridService
             return asset;
         }
 
-        public AssetBase Get(string id, string ForeignAssetService)
+        public AssetBase Get(string id, string ForeignAssetService, bool dummy)
         {
             return null;
         }

+ 1 - 1
OpenSim/Services/HypergridService/HGRemoteAssetService.cs

@@ -117,7 +117,7 @@ namespace OpenSim.Services.HypergridService
             return asset;
         }
 
-        public AssetBase Get(string id, string ForeignAssetService)
+        public AssetBase Get(string id, string ForeignAssetService, bool dummy)
         {
             return null;
         }

+ 2 - 2
OpenSim/Services/Interfaces/IAssetService.cs

@@ -40,8 +40,8 @@ namespace OpenSim.Services.Interfaces
         /// <param name="id"></param>
         /// <returns></returns>
         AssetBase Get(string id);
-        AssetBase Get(string id, string ForeignAssetService);
-
+        AssetBase Get(string id, string ForeignAssetService, bool StoreOnLocalGrid);
+        
         /// <summary>
         /// Get an asset's metadata
         /// </summary>