feat: optimize event slow exec cache

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2022-11-28 17:14:29 +08:00
parent 597bdb721a
commit 72673b2a67
7 changed files with 38 additions and 20 deletions

View File

@ -13,9 +13,9 @@
"ug": "yarn upgrade-interactive --latest",
"np": "./script/push.sh",
"lsp": "npm login -scope=@ccms",
"lp": "lerna publish --verify-access",
"lpb": "lerna publish --preid beta --dist-tag beta --verify-access",
"lpc": "lerna publish --canary --preid beta --pre-dist-tag beta --verify-access",
"lp": "lerna publish --verify-access --force-publish",
"lpb": "lerna publish --preid beta --dist-tag beta --verify-access --force-publish",
"lpc": "lerna publish --canary --preid beta --pre-dist-tag beta --verify-access --force-publish",
"lpf": "lerna publish from-package --yes"
},
"workspaces": [

View File

@ -26,6 +26,7 @@ export namespace event {
private mapEvent = [];
private listenerMap = [];
private cacheSlowEventKey = {};
protected baseEventDir = '';
@ -92,17 +93,23 @@ export namespace event {
return eventCls
}
execute(name, exec, eventCls) {
/**
*
* @param name
* @param exec
* @param eventCls
* @returns
*/
createExecute(name, exec, eventCls) {
return (...args: any[]) => {
let event = args[args.length - 1]
try {
let event = args[args.length - 1]
if (eventCls.isAssignableFrom(event.getClass())) {
let time = Date.now()
exec(event)
let cost = Date.now() - time
if (cost > global.ScriptSlowExecuteTime) {
console.i18n("ms.api.event.execute.slow", { name, event: this.class2Name(eventCls), cost })
}
if (!eventCls.isAssignableFrom(event.getClass())) { return }
let time = Date.now(); exec(event); let cost = Date.now() - time
if (cost > global.ScriptSlowExecuteTime) {
let eventKey = `${name}-${this.class2Name(eventCls)}`
if (!this.cacheSlowEventKey[eventKey]) { return this.cacheSlowEventKey[eventKey] = cost }
console.i18n("ms.api.event.execute.slow", { name, event: this.class2Name(eventCls), cost })
}
} catch (ex: any) {
console.i18n("ms.api.event.execute.error", { name, event: this.class2Name(eventCls), ex })
@ -135,7 +142,7 @@ export namespace event {
// noinspection JSUnusedGlobalSymbols
var listener = this.register(
eventCls,
this.execute(name, exec, eventCls),
this.createExecute(name, exec, eventCls),
priority,
ignoreCancel
)

View File

@ -185,15 +185,25 @@ export namespace server {
}
}
}
if (this.rootLogger.class.name.indexOf('slf4j') !== -1) {
try {
let LogManager = Java.type('org.apache.logging.log4j.LogManager')
this.rootLogger = LogManager.getLogger('ROOT')
} catch (error: any) {
if (global.debug) {
console.ex(error)
}
}
}
if (this.rootLogger && this.rootLogger.class.name.indexOf('Logger') === -1) {
console.error('Error Logger Class: ' + this.rootLogger.class.name)
this.rootLogger = undefined
}
if (!this.rootLogger) { console.error("Can't found rootLogger!") }
// get root logger
for (let index = 0; index < 5 && this.rootLogger.parent; index++) {
this.rootLogger = this.rootLogger.parent
}
if (!this.rootLogger) { console.error("Can't found rootLogger!") }
this.container.bind(constants.ServiceIdentifier.RootLogger).toConstantValue(this.rootLogger)
}
}

View File

@ -78,7 +78,7 @@ export class PluginCommandManager {
permission = `${pluginInstance.description.name.toLocaleLowerCase()}.${command}.${subcommand || 'main'}`
}
if (!sender.hasPermission(permission)) {
return pluginInstance.logger.sender(sender, `§c你需要 ${permission} 权限 才可执行此命令.`)
return pluginInstance.logger.sender(sender, `§c你需要 §4${permission} §c权限 才可执行此命令.`)
}
}
args.shift()
@ -98,7 +98,7 @@ export class PluginCommandManager {
return (args.length == 1 ? cmdSubCache : []).concat(originCompleter?.apply(pluginInstance, [sender, command, args]) || [])
}
}
if (!cmdCompleter) { console.warn(`[${pluginInstance.description.name}] command ${cmd.name} is not registry tabCompleter`) }
if (!cmdCompleter) { console.debug(`[${pluginInstance.description.name}] command ${cmd.name} is not registry tabCompleter`) }
return [cmdExecutor, cmdCompleter]
}
}

View File

@ -7,8 +7,7 @@ import { interfaces } from './interfaces'
import { getPluginConfigMetadata } from './utils'
import { PluginConfigLoader } from './config/interfaces'
import './config/loader/json-loader'
import './config/loader/yaml-loader'
import './config/loader'
@provideSingleton(PluginConfigManager)
export class PluginConfigManager {

View File

@ -98,6 +98,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
try {
this.loadAndRequirePlugin(loadMetadata)
} catch (error: any) {
console.console(`§c扫描器 §4${scanner.type} §c文件 §4${loadMetadata.file.toString().replace(root, '')} §c编译失败 请提供下列错误给开发者`)
console.ex(error)
}
}

View File

@ -2,7 +2,7 @@ import { EventEmitter } from "events"
import * as parser_v4 from "../engine.io-parser"
import * as parser_v3 from "./parser-v3"
// import debugModule from "debug"
import { IncomingMessage } from "http"
// import { IncomingMessage } from "http"
import { Packet } from "../engine.io-parser"
// const debug = debugModule("engine:transport")
@ -24,7 +24,8 @@ export abstract class Transport extends EventEmitter {
protected _readyState: string
protected discarded: boolean
protected parser: any
protected req: IncomingMessage & { cleanup: Function }
// protected req: IncomingMessage & { cleanup: Function }
protected req: { cleanup: Function }
protected supportsBinary: boolean
get readyState() {