From 540f4bcbf421e3c6b10d43c5730b5f847d739aaa Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Tue, 15 Mar 2022 15:00:22 +0800 Subject: [PATCH] =?UTF-8?q?[manager,webapp]fix=20=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=85=A8=E5=B1=80=E7=9B=91=E6=8E=A7=E6=90=9C=E7=B4=A2=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E5=BC=82=E5=B8=B8=20(#28)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../collector/collect/common/cache/CommonCache.java | 7 +++++-- .../usthe/manager/controller/MonitorsController.java | 12 ++++++++++-- .../src/app/layout/basic/widgets/search.component.ts | 8 ++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/collector/src/main/java/com/usthe/collector/collect/common/cache/CommonCache.java b/collector/src/main/java/com/usthe/collector/collect/common/cache/CommonCache.java index 819b9cb..014a62e 100644 --- a/collector/src/main/java/com/usthe/collector/collect/common/cache/CommonCache.java +++ b/collector/src/main/java/com/usthe/collector/collect/common/cache/CommonCache.java @@ -121,15 +121,17 @@ public class CommonCache { timeoutMap.put(key, new Long[]{currentTime, DEFAULT_CACHE_TIMEOUT}); } else if (cacheTime[0] + cacheTime[1] < currentTime) { // 过期了 discard 关闭这个cache的资源 + log.warn("[cache] clean the timeout cache, key {}", key); timeoutMap.remove(key); cacheMap.remove(key); if (value instanceof CacheCloseable) { + log.warn("[cache] close the timeout cache, key {}", key); ((CacheCloseable)value).close(); } } }); } catch (Exception e) { - log.error("clean timeout cache error: {}.", e.getMessage(), e); + log.error("[cache] clean timeout cache error: {}.", e.getMessage(), e); } } @@ -177,13 +179,14 @@ public class CommonCache { return Optional.empty(); } if (cacheTime[0] + cacheTime[1] < System.currentTimeMillis()) { - log.warn("[cache] is timeout, key {}.", key); + log.warn("[cache] is timeout, remove it, key {}.", key); timeoutMap.remove(key); cacheMap.remove(key); return Optional.empty(); } Object value = cacheMap.get(key); if (value == null) { + log.error("[cache] value is null, remove it, key {}.", key); cacheMap.remove(key); timeoutMap.remove(key); } else if (refreshCache) { diff --git a/manager/src/main/java/com/usthe/manager/controller/MonitorsController.java b/manager/src/main/java/com/usthe/manager/controller/MonitorsController.java index 53be6f6..474c3f8 100644 --- a/manager/src/main/java/com/usthe/manager/controller/MonitorsController.java +++ b/manager/src/main/java/com/usthe/manager/controller/MonitorsController.java @@ -79,9 +79,17 @@ public class MonitorsController { orList.add(predicateName); } Predicate[] orPredicates = new Predicate[orList.size()]; - Predicate orPredicate = criteriaBuilder.and(orList.toArray(orPredicates)); + Predicate orPredicate = criteriaBuilder.or(orList.toArray(orPredicates)); - return query.where(andPredicate,orPredicate).getRestriction(); + if (andPredicate.getExpressions().isEmpty() && orPredicate.getExpressions().isEmpty()) { + return query.where().getRestriction(); + } else if (andPredicate.getExpressions().isEmpty()) { + return query.where(orPredicate).getRestriction(); + } else if (orPredicate.getExpressions().isEmpty()) { + return query.where(andPredicate).getRestriction(); + } else { + return query.where(andPredicate,orPredicate).getRestriction(); + } }; // 分页是必须的 Sort sortExp = Sort.by(new Sort.Order(Sort.Direction.fromString(order), sort)); diff --git a/web-app/src/app/layout/basic/widgets/search.component.ts b/web-app/src/app/layout/basic/widgets/search.component.ts index 9120558..05f37cb 100644 --- a/web-app/src/app/layout/basic/widgets/search.component.ts +++ b/web-app/src/app/layout/basic/widgets/search.component.ts @@ -96,7 +96,11 @@ export class HeaderSearchComponent implements AfterViewInit, OnDestroy { searchMonitors$.unsubscribe(); if (message.code === 0) { let page = message.data; - this.options = page.content; + if (page.content != undefined) { + this.options = page.content; + } else { + this.options = []; + } this.cdr.detectChanges(); } else { console.warn(message.msg); @@ -118,7 +122,7 @@ export class HeaderSearchComponent implements AfterViewInit, OnDestroy { qBlur(): void { this.focus = false; this.searchToggled = false; - this.options.length = 0; + this.options = []; this.toggleChangeChange.emit(false); }