ntminer 5 years ago
parent
commit
a48d4cb347

+ 8 - 0
src/NTMinerDataSchemas/Core/Gpus/GpuName.cs

@@ -1,11 +1,19 @@
 namespace NTMiner.Core.Gpus {
     public class GpuName : IGpuName {
+        public static bool IsValidTotalMemory(ulong value) {
+            return value >= 2 * NTKeyword.ULongG;
+        }
+
         public GpuName() { }
 
         public string Name { get; set; }
 
         public ulong TotalMemory { get; set; }
 
+        public bool IsValid() {
+            return !string.IsNullOrEmpty(Name) && IsValidTotalMemory(TotalMemory);
+        }
+
         public override bool Equals(object obj) {
             if (obj == null) {
                 return false;

+ 1 - 0
src/NTMinerServer/Core/Redis/IGpuNameRedis.cs

@@ -6,5 +6,6 @@ namespace NTMiner.Core.Redis {
     public interface IGpuNameRedis {
         Task<List<GpuName>> GetAllAsync();
         Task SetAsync(GpuName gpuName);
+        Task SetAsync(List<GpuName> gpuNames);
     }
 }

+ 11 - 1
src/NTMinerServer/Core/Redis/Impl/GpuNameRedis.cs

@@ -1,6 +1,7 @@
 using NTMiner.Core.Gpus;
 using StackExchange.Redis;
 using System.Collections.Generic;
+using System.Linq;
 using System.Threading.Tasks;
 
 namespace NTMiner.Core.Redis.Impl {
@@ -30,11 +31,20 @@ namespace NTMiner.Core.Redis.Impl {
 
         public Task SetAsync(GpuName gpuName) {
             // 忽略显存小于2G的卡
-            if (gpuName == null || string.IsNullOrEmpty(gpuName.Name) || gpuName.TotalMemory < 2 * NTKeyword.ULongG) {
+            if (gpuName == null || !gpuName.IsValid()) {
                 return TaskEx.CompletedTask;
             }
             var db = _connection.GetDatabase();
             return db.HashSetAsync(_redisKeyGpuNameByClientId, gpuName.ToString(), VirtualRoot.JsonSerializer.Serialize(gpuName));
         }
+
+        public Task SetAsync(List<GpuName> gpuNames) {
+            if (gpuNames == null || gpuNames.Count == 0) {
+                return TaskEx.CompletedTask;
+            }
+            gpuNames = gpuNames.Where(a => a.IsValid()).ToList();
+            var db = _connection.GetDatabase();
+            return db.HashSetAsync(_redisKeyGpuNameByClientId, gpuNames.Select(a => new HashEntry(a.ToString(), VirtualRoot.JsonSerializer.Serialize(a))).ToArray());
+        }
     }
 }

+ 1 - 1
src/WebApiServer/Core/Impl/GpuNameSet.cs

@@ -14,7 +14,7 @@ namespace NTMiner.Core.Impl {
         /// <param name="gpuName"></param>
         /// <param name="gpuTotalMemory"></param>
         public void Add(string gpuName, ulong gpuTotalMemory) {
-            if (string.IsNullOrEmpty(gpuName) || gpuTotalMemory < 2 * NTKeyword.ULongG) {
+            if (string.IsNullOrEmpty(gpuName) || !GpuName.IsValidTotalMemory(gpuTotalMemory)) {
                 return;
             }
             _hashSet.Add(new GpuName {