diff --git a/YD_AllHeartRates.Api/Mqtt/MqttBackgroundService.cs b/YD_AllHeartRates.Api/Mqtt/MqttBackgroundService.cs index 6ccbcc8..c8233b2 100644 --- a/YD_AllHeartRates.Api/Mqtt/MqttBackgroundService.cs +++ b/YD_AllHeartRates.Api/Mqtt/MqttBackgroundService.cs @@ -89,8 +89,11 @@ namespace YD_AllHeartRates.Api.Mqtt List studentList; List devices; - studentList = _caching.Get>(AppSettings.StudentListCacheKey); - devices = _caching.Get>(AppSettings.DeviceListCacheKey); + var studentListCacheKey = $"{AppSettings.StudentListCacheKey}_{AppSettings.SchoolCode}"; + var deviceListCacheKey = $"{AppSettings.DeviceListCacheKey}_{AppSettings.SchoolCode}"; + + studentList = _caching.Get>(studentListCacheKey); + devices = _caching.Get>(deviceListCacheKey); if (studentList == null || devices == null) { @@ -114,10 +117,10 @@ namespace YD_AllHeartRates.Api.Mqtt DeviceType = d.DeviceType, }).ToList(); - devices = _smartSportsContext.Device.Where(x => x.SchoolCode == AppSettings.SchoolCode).ToList(); + devices = _smartSportsContext.Device.Where(x => x.SchoolCode == AppSettings.SchoolCode && !string.IsNullOrWhiteSpace(x.StudentNo)).ToList(); - _caching.AddObject(AppSettings.StudentListCacheKey, studentList, 28800); - _caching.AddObject(AppSettings.DeviceListCacheKey, devices, 28800); + _caching.AddObject(studentListCacheKey, studentList, 28800); + _caching.AddObject(deviceListCacheKey, devices, 28800); } var heartRateEntities = new ConcurrentBag(); diff --git a/YD_AllHeartRates.Api/Utilities/AppSettings.cs b/YD_AllHeartRates.Api/Utilities/AppSettings.cs index bf6ef4a..6677d0f 100644 --- a/YD_AllHeartRates.Api/Utilities/AppSettings.cs +++ b/YD_AllHeartRates.Api/Utilities/AppSettings.cs @@ -14,8 +14,9 @@ public static string[] CorsUrls { get; set; } public static MqttConfig Mqtt { get; set; } - public static string StudentListCacheKey = $"student_list_{SchoolCode}"; - public static string DeviceListCacheKey = $"device_list_{SchoolCode}"; + public static string StudentListCacheKey = $"student_list"; + + public static string DeviceListCacheKey = $"device_list"; public static string SchoolCode { get; set; } public static void Init(IConfiguration configuration)