1010
1111use function __ ;
1212use function array_change_key_case ;
13+ use function array_key_exists ;
1314use function count ;
15+ use function number_format ;
1416
1517use const CASE_LOWER ;
1618
@@ -30,10 +32,8 @@ public function getList(bool $showExecuting, bool $showFullSql, string $orderByF
3032 $ sqlQuery = $ showFullSql
3133 ? 'SHOW FULL PROCESSLIST '
3234 : 'SHOW PROCESSLIST ' ;
33- if (
34- ($ orderByField !== '' && $ sortOrder !== '' )
35- || $ showExecuting
36- ) {
35+ $ useIS = $ showExecuting || ($ orderByField !== '' && $ sortOrder !== '' );
36+ if ($ useIS ) {
3737 $ urlParams ['order_by_field ' ] = $ orderByField ;
3838 $ urlParams ['sort_order ' ] = $ sortOrder ;
3939 $ urlParams ['showExecuting ' ] = $ showExecuting ;
@@ -54,6 +54,16 @@ public function getList(bool $showExecuting, bool $showFullSql, string $orderByF
5454 // Array keys need to modify due to the way it has used
5555 // to display column values
5656 $ process = array_change_key_case ($ process , CASE_LOWER );
57+
58+ $ progress = ! empty ($ process ['Progress ' ]) ? $ process ['Progress ' ] : '--- ' ;
59+ if ($ useIS && ! empty ($ process ['Progress ' ])) {
60+ $ stage = array_key_exists ('Stage ' , $ process ) ? (int ) $ process ['Stage ' ] : null ;
61+ $ maxStage = array_key_exists ('Max_stage ' , $ process ) ? (int ) $ process ['Max_stage ' ] : null ;
62+ if ($ stage !== null && $ maxStage !== null && $ maxStage > 1 ) {
63+ $ progress = number_format (($ stage - 1 ) / $ maxStage * 100 + ((float ) $ progress ) / $ maxStage , 3 );
64+ }
65+ }
66+
5767 $ rows [] = [
5868 'id ' => $ process ['id ' ],
5969 'user ' => $ process ['user ' ],
@@ -62,7 +72,7 @@ public function getList(bool $showExecuting, bool $showFullSql, string $orderByF
6272 'command ' => $ process ['command ' ],
6373 'time ' => $ process ['time ' ],
6474 'state ' => ! empty ($ process ['state ' ]) ? $ process ['state ' ] : '--- ' ,
65- 'progress ' => ! empty ( $ process [ ' progress ' ]) ? $ process [ ' progress ' ] : ' --- ' ,
75+ 'progress ' => $ progress ,
6676 'info ' => ! empty ($ process ['info ' ]) ? Generator::formatSql ($ process ['info ' ], ! $ showFullSql ) : '--- ' ,
6777 ];
6878 }
0 commit comments