소스 검색

Blob缓存更新

CrazyIter_Bin 4 년 전
부모
커밋
9c17e94ae2
2개의 변경된 파일40개의 추가작업 그리고 38개의 파일을 삭제
  1. 8 8
      TEAMModelOS.SDK/DI/AzureStorage/AzureStorageBlobExtensions.cs
  2. 32 30
      TEAMModelOS/Controllers/Core/BlobController.cs

+ 8 - 8
TEAMModelOS.SDK/DI/AzureStorage/AzureStorageBlobExtensions.cs

@@ -12,6 +12,7 @@ using Azure.Storage.Blobs.Specialized;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
+using Azure.Core;
 
 
 namespace TEAMModelOS.SDK.DI
 namespace TEAMModelOS.SDK.DI
 {
 {
@@ -41,7 +42,7 @@ namespace TEAMModelOS.SDK.DI
         /// <summary>
         /// <summary>
         /// 取得指定前置詞的 Blob 名稱的總大小(Bytes),例如指定目錄名稱為前置詞
         /// 取得指定前置詞的 Blob 名稱的總大小(Bytes),例如指定目錄名稱為前置詞
         /// </summary>      
         /// </summary>      
-        /// <param name="prefix">篩選開頭名稱,Null代表容器總大小</param>
+        /// <param name="urls">多个文件的连接/param>
         /// <returns>總大小(Bytes),如果為Null代表查無前置詞或者發生錯誤</returns>
         /// <returns>總大小(Bytes),如果為Null代表查無前置詞或者發生錯誤</returns>
         public static async Task<long?> GetBlobsSize(this BlobContainerClient client, List<string>urls)
         public static async Task<long?> GetBlobsSize(this BlobContainerClient client, List<string>urls)
         {
         {
@@ -49,13 +50,12 @@ namespace TEAMModelOS.SDK.DI
             try
             try
             {
             {
                 foreach (var url in urls) {
                 foreach (var url in urls) {
-                   var eurl = "/" + System.Web.HttpUtility.UrlDecode(url.ToString(), Encoding.UTF8);
-                    client.GetBlobClient(eurl);
-                    if (client.Exists()) {
-                        await foreach (var item in client.GetBlobsAsync(BlobTraits.None, BlobStates.None))
-                        {
-                            size += item.Properties.ContentLength;
-                        }
+                 
+                    var eurl = System.Web.HttpUtility.UrlDecode(url.ToString(), Encoding.UTF8);
+                    var blob = client.GetBlobClient(eurl);
+                    if (blob.Exists()) {
+                        var props = await blob.GetPropertiesAsync();
+                        size += props.Value.ContentLength;
                     }
                     }
                 }
                 }
                 return size;
                 return size;

+ 32 - 30
TEAMModelOS/Controllers/Core/BlobController.cs

@@ -237,16 +237,16 @@ namespace TEAMModelOS.Controllers.Core
             
             
             request.TryGetProperty("containerName", out JsonElement containerName);
             request.TryGetProperty("containerName", out JsonElement containerName);
             var name =containerName.GetString();
             var name =containerName.GetString();
-            RedisValue value = default;
-            value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", name);
-            if (value != default && !value.IsNullOrEmpty)
-            {
-                JsonElement record = value.ToString().ToObject<JsonElement>();
-                if (record.TryGetInt64(out long blobsize))
-                {
-                    return Ok(new { size= blobsize });
-                }
-            }
+            //RedisValue value = default;
+            //value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", name);
+            //if (value != default && !value.IsNullOrEmpty)
+            //{
+            //    JsonElement record = value.ToString().ToObject<JsonElement>();
+            //    if (record.TryGetInt64(out long blobsize))
+            //    {
+            //        return Ok(new { size= blobsize });
+            //    }
+            //}
             var client = _azureStorage.GetBlobContainerClient(name);
             var client = _azureStorage.GetBlobContainerClient(name);
             var size = await client.GetBlobsSize();
             var size = await client.GetBlobsSize();
             await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size);
             await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size);
@@ -254,7 +254,7 @@ namespace TEAMModelOS.Controllers.Core
         }
         }
         /// <summary>
         /// <summary>
         /// 测试单个文本内容的上传
         /// 测试单个文本内容的上传
-        /// {"containerName":"hbcn","updateSize":5000,"deleteurl":[]}
+        /// {"containerName":"hbcn","uploadSize":5000,"optUrls":[]}
         /// </summary>
         /// </summary>
         /// <param name="azureBlobSASDto"></param>
         /// <param name="azureBlobSASDto"></param>
         /// <returns></returns>
         /// <returns></returns>
@@ -262,27 +262,29 @@ namespace TEAMModelOS.Controllers.Core
         public async Task<ActionResult> updateBlobsSize(JsonElement request)
         public async Task<ActionResult> updateBlobsSize(JsonElement request)
         {
         {
             request.TryGetProperty("containerName", out JsonElement containerName);
             request.TryGetProperty("containerName", out JsonElement containerName);
+            request.TryGetProperty("optUrls", out JsonElement optUrls);
+            request.TryGetProperty("uploadSize", out JsonElement uploadSize);
             var name = containerName.GetString();
             var name = containerName.GetString();
+            uploadSize.TryGetInt64(out long size);
+            var urls = optUrls.ToObject<List<string>>();
             var client = _azureStorage.GetBlobContainerClient(name);
             var client = _azureStorage.GetBlobContainerClient(name);
-            var size = await client.GetBlobsSize();
-            return Ok(new { size });
-        }
-        /// <summary>
-        /// 测试单个文本内容的上传
-        /// {"containerName":"hbcn","updateSize":5000,"deleteurl":[]}
-        /// </summary>
-        /// <param name="azureBlobSASDto"></param>
-        /// <returns></returns>
-        [HttpPost("get-blobUrlsize")]
-        public async Task<ActionResult> getBlobUrlsize(JsonElement request)
-        {
-            request.TryGetProperty("containerName", out JsonElement containerName);
-            request.TryGetProperty("deleteUrl", out JsonElement deleteUrl);
-            var name = containerName.GetString();
-            var urls = deleteUrl.ToObject<List<string>>();
-            var client = _azureStorage.GetBlobContainerClient(name);
-            var size = await client.GetBlobsSize(urls);
-            return Ok(new { size });
+            var urlsSize = await client.GetBlobsSize(urls);
+            long? disSize= size - urlsSize;
+            RedisValue value = default;
+            long? useSize = 0;
+            long blobSize = 0;
+            value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", name);
+            if (value != default && !value.IsNullOrEmpty)
+            {
+                JsonElement record = value.ToString().ToObject<JsonElement>();
+                if (record.TryGetInt64(out   blobSize))
+                {
+                    useSize = blobSize;
+                }
+            }
+            useSize = useSize + disSize;
+            await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, useSize);
+            return Ok(new { disSize, urlsSize , useSize , blobSize });
         }
         }
 
 
         private static (string, string) BlobUrlString(string sasUrl)
         private static (string, string) BlobUrlString(string sasUrl)