Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit b7803d9

Browse files
committed
test for extensions2 using stats
1 parent 9a58b30 commit b7803d9

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

includes/data/query/Stats.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,42 @@ private function getTopExtensions( int $limit, DBConnRef $dbr ): array {
120120
return $ret;
121121
}
122122

123+
/**
124+
* @param int $limit
125+
* @param DBConnRef $dbr
126+
*
127+
* @return array
128+
*/
129+
private function getTopExtensions2( int $limit, DBConnRef $dbr ): array {
130+
131+
$select = [ Structure::DBTABLE_EXTENSIONS_LINK . '.' . Structure::EXTENSION_LINK_ID ];
132+
$from = Structure::DBTABLE_WIKIS;
133+
$res = $dbr->newSelectQueryBuilder()->select( $select )->from( $from )->
134+
leftJoin( Structure::DBTABLE_SCRAPE,
135+
null,
136+
Structure::DBTABLE_WIKIS . '.' . Structure::WIKI_LAST_SR_RCRD . '=' . Structure::DBTABLE_SCRAPE . '.' . Structure::SR_ID )->
137+
leftJoin( Structure::DBTABLE_EXTENSIONS_LINK,
138+
null,
139+
Structure::DBTABLE_SCRAPE . '.' . Structure::SCRAPE_VR_ID . '=' . Structure::DBTABLE_EXTENSIONS_LINK . '.' . Structure::EXTENSION_LINK_VID )->
140+
caller( __METHOD__ )->fetchResultSet();
141+
$ids = [];
142+
if ( $res->numRows() > 0 ) {
143+
while ( $row = $res->fetchRow() ) {
144+
$ids[] = $row[ Structure::EXTENSION_LINK_ID ];
145+
}
146+
}
147+
//var_dump ( $ids );
148+
$nRes = [];
149+
$counter = array_count_values( $ids );
150+
$t=0;
151+
foreach ( $counter as $k => $v ) {
152+
$nRes[$t]['k'] = $k;
153+
$nRes[$t]['v'] = $v;
154+
$t++;
155+
}
156+
return $nRes;
157+
}
158+
123159
/**
124160
* @param string $action
125161
* @param int $limit
@@ -136,6 +172,10 @@ public function doQuery( string $action, int $limit = 10, string $export = "tabl
136172
$result = $this->getTopExtensions( $limit,
137173
$dbr );
138174
break;
175+
case "extensions2":
176+
$result = $this->getTopExtensions2( $limit,
177+
$dbr );
178+
break;
139179
case "skins":
140180
$result = $this->getTopSkins( $limit,
141181
$dbr );
@@ -152,6 +192,12 @@ public function doQuery( string $action, int $limit = 10, string $export = "tabl
152192
$this->structure->returnTableColumns( Structure::DBTABLE_EXTENSIONS ) ),
153193
true );
154194
}
195+
if ( $action === "extensions2" ) {
196+
return Utils::renderTable( $result,
197+
'Top ' . $limit . ' used extensions',
198+
[ 'id', 'hits' ],
199+
true );
200+
}
155201
if ( $action === "skins" ) {
156202
return Utils::renderTable( $result,
157203
'Top ' . $limit . ' used skins',

0 commit comments

Comments
 (0)