[manager,webapp]fix 页面全局监控搜索结果异常

This commit is contained in:
tomsun28
2022-03-15 14:58:26 +08:00
parent 9eb3b9842d
commit ad1b1b48db
3 changed files with 21 additions and 6 deletions

View File

@@ -121,15 +121,17 @@ public class CommonCache {
timeoutMap.put(key, new Long[]{currentTime, DEFAULT_CACHE_TIMEOUT}); timeoutMap.put(key, new Long[]{currentTime, DEFAULT_CACHE_TIMEOUT});
} else if (cacheTime[0] + cacheTime[1] < currentTime) { } else if (cacheTime[0] + cacheTime[1] < currentTime) {
// 过期了 discard 关闭这个cache的资源 // 过期了 discard 关闭这个cache的资源
log.warn("[cache] clean the timeout cache, key {}", key);
timeoutMap.remove(key); timeoutMap.remove(key);
cacheMap.remove(key); cacheMap.remove(key);
if (value instanceof CacheCloseable) { if (value instanceof CacheCloseable) {
log.warn("[cache] close the timeout cache, key {}", key);
((CacheCloseable)value).close(); ((CacheCloseable)value).close();
} }
} }
}); });
} catch (Exception e) { } 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(); return Optional.empty();
} }
if (cacheTime[0] + cacheTime[1] < System.currentTimeMillis()) { 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); timeoutMap.remove(key);
cacheMap.remove(key); cacheMap.remove(key);
return Optional.empty(); return Optional.empty();
} }
Object value = cacheMap.get(key); Object value = cacheMap.get(key);
if (value == null) { if (value == null) {
log.error("[cache] value is null, remove it, key {}.", key);
cacheMap.remove(key); cacheMap.remove(key);
timeoutMap.remove(key); timeoutMap.remove(key);
} else if (refreshCache) { } else if (refreshCache) {

View File

@@ -79,9 +79,17 @@ public class MonitorsController {
orList.add(predicateName); orList.add(predicateName);
} }
Predicate[] orPredicates = new Predicate[orList.size()]; 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)); Sort sortExp = Sort.by(new Sort.Order(Sort.Direction.fromString(order), sort));

View File

@@ -96,7 +96,11 @@ export class HeaderSearchComponent implements AfterViewInit, OnDestroy {
searchMonitors$.unsubscribe(); searchMonitors$.unsubscribe();
if (message.code === 0) { if (message.code === 0) {
let page = message.data; let page = message.data;
this.options = page.content; if (page.content != undefined) {
this.options = page.content;
} else {
this.options = [];
}
this.cdr.detectChanges(); this.cdr.detectChanges();
} else { } else {
console.warn(message.msg); console.warn(message.msg);
@@ -118,7 +122,7 @@ export class HeaderSearchComponent implements AfterViewInit, OnDestroy {
qBlur(): void { qBlur(): void {
this.focus = false; this.focus = false;
this.searchToggled = false; this.searchToggled = false;
this.options.length = 0; this.options = [];
this.toggleChangeChange.emit(false); this.toggleChangeChange.emit(false);
} }