|
@@ -170,8 +170,8 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
/// </summary>
|
|
|
/// <param name="azureBlobSASDto"></param>
|
|
|
/// <returns></returns>
|
|
|
- [HttpPost("get-blobsize")]
|
|
|
- public async Task<ActionResult> GetBlobsSize(JsonElement request)
|
|
|
+ [HttpPost("used-space")]
|
|
|
+ public async Task<ActionResult> UsedSpace(JsonElement request)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
@@ -194,68 +194,52 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // request.TryGetProperty("cache", out JsonElement cache);
|
|
|
var name =containerName.GetString();
|
|
|
- //if (cache.GetBoolean())
|
|
|
- //{
|
|
|
- long blobsize = 0;
|
|
|
- RedisValue value = default;
|
|
|
- value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", name);
|
|
|
- if (value != default && !value.IsNullOrEmpty)
|
|
|
+ long blobsize = 0;
|
|
|
+ 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 blobsize))
|
|
|
{
|
|
|
- JsonElement record = value.ToString().ToObject<JsonElement>();
|
|
|
- if (record.TryGetInt64(out blobsize))
|
|
|
- {
|
|
|
- }
|
|
|
}
|
|
|
- else
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var client = _azureStorage.GetBlobContainerClient(name);
|
|
|
+ var size = await client.GetBlobsCatalogSize();
|
|
|
+ await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size.Item1);
|
|
|
+ foreach (var key in size.Item2.Keys)
|
|
|
{
|
|
|
- var client = _azureStorage.GetBlobContainerClient(name);
|
|
|
- var size = await client.GetBlobsCatalogSize();
|
|
|
- await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size.Item1);
|
|
|
- foreach (var key in size.Item2.Keys)
|
|
|
- {
|
|
|
- await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", key);
|
|
|
- await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
|
|
|
- }
|
|
|
- return Ok(new { size = size.Item1, catalog = size.Item2 ,teach });
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", key);
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
|
|
|
}
|
|
|
- Dictionary<string, double> catalog = new Dictionary<string, double>();
|
|
|
- SortedSetEntry[] Scores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Blob:Catalog:{name}");
|
|
|
- if (Scores != null)
|
|
|
+ return Ok(new { size = size.Item1, catalog = size.Item2 ,teach });
|
|
|
+ }
|
|
|
+ Dictionary<string, double> catalog = new Dictionary<string, double>();
|
|
|
+ SortedSetEntry[] Scores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Blob:Catalog:{name}");
|
|
|
+ if (Scores != null)
|
|
|
+ {
|
|
|
+ foreach (var score in Scores)
|
|
|
{
|
|
|
- foreach (var score in Scores)
|
|
|
- {
|
|
|
- double val = score.Score;
|
|
|
- string key = score.Element.ToString();
|
|
|
- catalog.Add(key, val);
|
|
|
- }
|
|
|
- return Ok(new { size = blobsize, catalog = catalog, teach });
|
|
|
+ double val = score.Score;
|
|
|
+ string key = score.Element.ToString();
|
|
|
+ catalog.Add(key, val);
|
|
|
}
|
|
|
- else {
|
|
|
- var client = _azureStorage.GetBlobContainerClient(name);
|
|
|
- var size = await client.GetBlobsCatalogSize();
|
|
|
- await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size.Item1);
|
|
|
- foreach (var key in size.Item2.Keys)
|
|
|
- {
|
|
|
- await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", key);
|
|
|
- await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
|
|
|
- }
|
|
|
- return Ok(new { size = size.Item1, catalog = size.Item2, teach });
|
|
|
+ return Ok(new { size = blobsize, catalog = catalog, teach });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ var client = _azureStorage.GetBlobContainerClient(name);
|
|
|
+ var size = await client.GetBlobsCatalogSize();
|
|
|
+ await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size.Item1);
|
|
|
+ foreach (var key in size.Item2.Keys)
|
|
|
+ {
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", key);
|
|
|
+ await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
|
|
|
}
|
|
|
- // }
|
|
|
- // else {
|
|
|
- //var client = _azureStorage.GetBlobContainerClient(name);
|
|
|
- //var size = await client.GetBlobsCatalogSize();
|
|
|
- //await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size.Item1);
|
|
|
- //foreach (var key in size.Item2.Keys)
|
|
|
- //{
|
|
|
- // await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", key);
|
|
|
- // await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", key, size.Item2[key].HasValue ? size.Item2[key].Value : 0);
|
|
|
- //}
|
|
|
- //return Ok(new { size = size.Item1, catalog = size.Item2, teach });
|
|
|
- // }
|
|
|
-
|
|
|
+ return Ok(new { size = size.Item1, catalog = size.Item2, teach });
|
|
|
+ }
|
|
|
}
|
|
|
catch (Exception ex){
|
|
|
await _dingDing.SendBotMsg($"IES5,{_option.Location},blon/get-blobsize()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
@@ -415,9 +399,6 @@ namespace TEAMModelOS.Controllers.Core
|
|
|
{
|
|
|
return BadRequest();
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/*
|