日常查询由mysql改为clickhouse
This commit is contained in:
@@ -7,6 +7,47 @@ Tea.context(function () {
|
||||
this.accessLogs = []
|
||||
this.isLoaded = false
|
||||
|
||||
this.mergeAccessLogs = function (newAccessLogs, regions, wafInfos) {
|
||||
let mergedLogs = newAccessLogs.concat(this.accessLogs)
|
||||
let result = []
|
||||
let seenRequestIds = {}
|
||||
|
||||
let that = this
|
||||
mergedLogs.forEach(function (accessLog) {
|
||||
if (accessLog == null) {
|
||||
return
|
||||
}
|
||||
|
||||
let requestId = accessLog.requestId || ""
|
||||
if (requestId.length > 0) {
|
||||
if (seenRequestIds[requestId] === true) {
|
||||
return
|
||||
}
|
||||
seenRequestIds[requestId] = true
|
||||
}
|
||||
|
||||
that.formatTime(accessLog)
|
||||
|
||||
let region = regions[accessLog.remoteAddr]
|
||||
if (typeof (region) == "string") {
|
||||
accessLog.region = region
|
||||
} else if (typeof accessLog.region != "string") {
|
||||
accessLog.region = ""
|
||||
}
|
||||
|
||||
let wafInfo = wafInfos[accessLog.firewallRuleSetId]
|
||||
if (accessLog.firewallRuleSetId > 0 && typeof (wafInfo) == "object") {
|
||||
accessLog.wafInfo = wafInfo
|
||||
} else if (typeof accessLog.wafInfo == "undefined") {
|
||||
accessLog.wafInfo = null
|
||||
}
|
||||
|
||||
result.push(accessLog)
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
this.load = function () {
|
||||
// 如果有弹窗时,暂时不更新
|
||||
if (teaweb.hasPopup()) {
|
||||
@@ -27,30 +68,17 @@ Tea.context(function () {
|
||||
nodeId: this.nodeId
|
||||
})
|
||||
.success(function (resp) {
|
||||
this.accessLogs = resp.data.accessLogs.concat(this.accessLogs)
|
||||
|
||||
// 添加区域信息
|
||||
let that = this
|
||||
this.accessLogs.forEach(function (accessLog) {
|
||||
that.formatTime(accessLog)
|
||||
if (typeof (resp.data.regions[accessLog.remoteAddr]) == "string") {
|
||||
accessLog.region = resp.data.regions[accessLog.remoteAddr]
|
||||
} else {
|
||||
accessLog.region = ""
|
||||
}
|
||||
if (accessLog.firewallRuleSetId > 0 && typeof (resp.data.wafInfos[accessLog.firewallRuleSetId]) == "object") {
|
||||
accessLog.wafInfo = resp.data.wafInfos[accessLog.firewallRuleSetId]
|
||||
} else {
|
||||
accessLog.wafInfo = null
|
||||
}
|
||||
})
|
||||
let newAccessLogs = resp.data.accessLogs || []
|
||||
this.accessLogs = this.mergeAccessLogs(newAccessLogs, resp.data.regions || {}, resp.data.wafInfos || {})
|
||||
|
||||
let max = 100
|
||||
if (this.accessLogs.length > max) {
|
||||
this.accessLogs = this.accessLogs.slice(0, max)
|
||||
}
|
||||
this.hasMore = resp.data.hasMore
|
||||
this.requestId = resp.data.requestId
|
||||
if (typeof resp.data.requestId == "string" && resp.data.requestId.length > 0) {
|
||||
this.requestId = resp.data.requestId
|
||||
}
|
||||
})
|
||||
.done(function () {
|
||||
if (!this.isLoaded) {
|
||||
@@ -79,4 +107,4 @@ Tea.context(function () {
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user