@@ -51,25 +51,35 @@ export default class RefreshPlayer implements ILifeCycleTask {
5151 } catch ( error ) { }
5252 } , 3000 ) ;
5353
54+ // 提前填充在线人数报表数据
5455 while ( this . playersChart . length < 60 ) {
5556 this . playersChart . push ( { value : "0" } ) ;
5657 }
58+ instance . info . playersChart = this . playersChart ;
5759
58- this . playersChartTask = setInterval ( async ( ) => {
59- try {
60- const result = await instance . execPreset ( "getPlayer" ) ;
61- if ( ! result ) return ;
62- this . playersChart . push ( {
63- value : result . current_players ? result . current_players : 0
64- } ) ;
65- if ( this . playersChart . length > 60 ) {
66- this . playersChart = this . playersChart . slice ( 1 , this . playersChart . length ) ;
67- }
68- instance . info . playersChart = this . playersChart ;
69- } catch ( error ) { }
60+ // 启动的时候先执行一次
61+ this . getPlayersChartData ( instance ) . then ( ( ) => { } ) ;
62+
63+ // 开启查询在线人数报表数据定时器
64+ this . playersChartTask = setInterval ( ( ) => {
65+ this . getPlayersChartData ( instance ) . then ( ( ) => { } ) ;
7066 } , 600000 ) ;
7167 }
7268
69+ async getPlayersChartData ( instance : Instance ) {
70+ try {
71+ const result = await instance . execPreset ( "getPlayer" ) ;
72+ if ( ! result ) return ;
73+ this . playersChart . push ( {
74+ value : result . current_players ? result . current_players : 0
75+ } ) ;
76+ if ( this . playersChart . length > 60 ) {
77+ this . playersChart = this . playersChart . slice ( 1 , this . playersChart . length ) ;
78+ }
79+ instance . info . playersChart = this . playersChart ;
80+ } catch ( error ) { }
81+ }
82+
7383 async stop ( instance : Instance ) {
7484 clearInterval ( this . task ) ;
7585 clearInterval ( this . playersChartTask ) ;
0 commit comments