9191let isNuiActive = false ;
9292
9393function NuiMessage ( msg ) {
94- window . SendNuiMessage ( JSON . stringify ( msg ) ) ;
94+ SendNuiMessage ( JSON . stringify ( msg ) ) ;
9595}
9696
9797function NuiCallback ( name , callback ) {
98- window . RegisterNuiCallbackType ( name ) ;
99- window . on ( `__cfx_nui:${ name } ` , ( data , cb ) => {
98+ RegisterNuiCallbackType ( name ) ;
99+ on ( `__cfx_nui:${ name } ` , ( data , cb ) => {
100100 callback ( data ) ;
101101 cb ( 'ok' ) ;
102102 } ) ;
@@ -105,42 +105,44 @@ function NuiCallback(name, callback) {
105105function setNuiActive ( boolean = true ) {
106106 if ( boolean !== isNuiActive ) {
107107 if ( boolean ) {
108- window . emitNet ( 'mysql-async:request-data' ) ;
108+ emitNet ( 'mysql-async:request-data' ) ;
109109 }
110+
110111 isNuiActive = boolean ;
111- NuiMessage ( { type : 'onToggleShow' } ) ;
112- window . SetNuiFocus ( boolean , boolean ) ;
112+ NuiMessage ( {
113+ type : 'onToggleShow'
114+ } ) ;
115+ SetNuiFocus ( boolean , boolean ) ;
113116 }
114117}
115118
116- window . RegisterCommand ( 'mysql' , ( ) => {
119+ RegisterCommand ( 'mysql' , ( ) => {
117120 setNuiActive ( ) ;
118121} , true ) ;
119-
120122NuiCallback ( 'close-explorer' , ( ) => {
121123 setNuiActive ( false ) ;
122124} ) ;
123-
124- window . setInterval ( ( ) => {
125+ setInterval ( ( ) => {
125126 if ( isNuiActive ) {
126- window . emitNet ( 'mysql-async:request-data' ) ;
127+ emitNet ( 'mysql-async:request-data' ) ;
127128 }
128129} , 300000 ) ;
129-
130- window . onNet ( 'mysql-async:update-resource-data' , ( resourceData ) => {
130+ onNet ( 'mysql-async:update-resource-data' , resourceData => {
131131 let arrayToSortAndMap = [ ] ;
132132 const resources = Object . keys ( resourceData ) ;
133+
133134 for ( let i = 0 ; i < resources . length ; i += 1 ) {
134135 if ( Object . prototype . hasOwnProperty . call ( resourceData , resources [ i ] ) ) {
135136 if ( Object . prototype . hasOwnProperty . call ( resourceData [ resources [ i ] ] , 'totalExecutionTime' ) ) {
136137 arrayToSortAndMap . push ( {
137138 resource : resources [ i ] ,
138139 queryTime : resourceData [ resources [ i ] ] . totalExecutionTime ,
139- count : resourceData [ resources [ i ] ] . queryCount ,
140+ count : resourceData [ resources [ i ] ] . queryCount
140141 } ) ;
141142 }
142143 }
143144 }
145+
144146 if ( arrayToSortAndMap . length > 0 ) {
145147 arrayToSortAndMap . sort ( ( a , b ) => a . queryTime - b . queryTime ) ;
146148 const len = arrayToSortAndMap . length ;
@@ -149,71 +151,63 @@ window.onNet('mysql-async:update-resource-data', (resourceData) => {
149151 const resourceA = a . resource . toLowerCase ( ) ;
150152 const resourceB = b . resource . toLowerCase ( ) ;
151153 let result = 0 ;
154+
152155 if ( resourceA < resourceB ) {
153156 result = - 1 ;
154157 } else if ( resourceA > resourceB ) {
155158 result = 1 ;
156159 }
160+
157161 return result ;
158162 } ) ;
159163 NuiMessage ( {
160164 type : 'onResourceLabels' ,
161- resourceLabels : arrayToSortAndMap . map ( ( el ) => el . resource ) ,
165+ resourceLabels : arrayToSortAndMap . map ( el => el . resource )
162166 } ) ;
163167 NuiMessage ( {
164168 type : 'onResourceData' ,
165- resourceData : [
166- {
167- data : arrayToSortAndMap . map ( ( el ) => el . queryTime ) ,
168- } ,
169- {
170- data : arrayToSortAndMap . map ( ( el ) => ( ( el . count > 0 ) ? el . queryTime / el . count : 0 ) ) ,
171- } ,
172- {
173- data : arrayToSortAndMap . map ( ( el ) => el . count ) ,
174- } ,
175- ] ,
169+ resourceData : [ {
170+ data : arrayToSortAndMap . map ( el => el . queryTime )
171+ } , {
172+ data : arrayToSortAndMap . map ( el => el . count > 0 ? el . queryTime / el . count : 0 )
173+ } , {
174+ data : arrayToSortAndMap . map ( el => el . count )
175+ } ]
176176 } ) ;
177177 }
178178} ) ;
179-
180- window . onNet ( 'mysql-async:update-time-data' , ( timeData ) => {
179+ onNet ( 'mysql-async:update-time-data' , timeData => {
181180 let timeArray = [ ] ;
181+
182182 if ( Array . isArray ( timeData ) ) {
183183 const len = timeData . length ;
184184 timeArray = timeData . filter ( ( _ , index ) => index > len - 31 ) ;
185185 }
186+
186187 if ( timeArray . length > 0 ) {
187188 NuiMessage ( {
188189 type : 'onTimeData' ,
189- timeData : [
190- {
191- data : timeArray . map ( ( el ) => el . totalExecutionTime ) ,
192- } ,
193- {
194- data : timeArray . map ( ( el ) => ( ( el . queryCount > 0 ) ? el . totalExecutionTime / el . queryCount
195- : 0 ) ) ,
196- } ,
197- {
198- data : timeArray . map ( ( el ) => el . queryCount ) ,
199- } ,
200- ] ,
190+ timeData : [ {
191+ data : timeArray . map ( el => el . totalExecutionTime )
192+ } , {
193+ data : timeArray . map ( el => el . queryCount > 0 ? el . totalExecutionTime / el . queryCount : 0 )
194+ } , {
195+ data : timeArray . map ( el => el . queryCount )
196+ } ]
201197 } ) ;
202198 }
203199} ) ;
204-
205- window . onNet ( 'mysql-async:update-slow-queries' , ( slowQueryData ) => {
206- const slowQueries = slowQueryData . map ( ( el ) => {
200+ onNet ( 'mysql-async:update-slow-queries' , slowQueryData => {
201+ const slowQueries = slowQueryData . map ( el => {
207202 const element = el ;
208203 element . queryTime = Math . round ( el . queryTime * 100 ) / 100 ;
209204 return element ;
210205 } ) ;
211206 NuiMessage ( {
212207 type : 'onSlowQueryData' ,
213- slowQueries,
208+ slowQueries
214209 } ) ;
215210} ) ;
216211
217-
218212/***/ } )
219213/******/ ] ) ;
0 commit comments