Jeroen De Dauw has submitted this change and it was merged.
Change subject: Use statistics from the stats table not Count(*)
......................................................................
Use statistics from the stats table not Count(*)
Its really not wise to count all the tables so directly use stats table.
Change-Id: I3966cae3efe3b9dc64b1f89b4c818430dbea5348
---
M includes/storage/SQLStore/StatisticsCollector.php
M tests/phpunit/includes/storage/sqlstore/StatisticsCollectorTest.php
2 files changed, 34 insertions(+), 39 deletions(-)
Approvals:
Nischayn22: Checked; Looks good to me, but someone else must approve
Jeroen De Dauw: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/storage/SQLStore/StatisticsCollector.php
b/includes/storage/SQLStore/StatisticsCollector.php
index 6ccf8c7..3d6930c 100644
--- a/includes/storage/SQLStore/StatisticsCollector.php
+++ b/includes/storage/SQLStore/StatisticsCollector.php
@@ -223,7 +223,7 @@
}
/**
- * Count property uses by counting rows in property tables
+ * Count property uses by summing up property statistics table
*
* @note subproperties that are part of container values are counted
* individually and it does not seem to be important to filter them by
@@ -237,16 +237,14 @@
wfProfileIn( __METHOD__ );
$count = 0;
- foreach ( $this->store->getPropertyTables() as $propertyTable )
{
- $res = $this->dbConnection->select(
- $propertyTable->getName(),
- 'COUNT(*) AS count',
- array(),
- __METHOD__
- );
- $row = $this->dbConnection->fetchObject( $res );
- $count += $row->count;
- }
+ $row = $this->dbConnection->selectRow(
+ array( $this->store->getStatisticsTable() ),
+ 'SUM( usage_count ) AS count',
+ array(),
+ __METHOD__
+ );
+
+ $count = $row ? $row->count : $count;
wfProfileOut( __METHOD__ );
return (int)$count;
@@ -261,30 +259,14 @@
wfProfileIn( __METHOD__ );
$count = 0;
- foreach ( $this->store->getPropertyTables() as $propertyTable )
{
- if ( !$propertyTable->isFixedPropertyTable() ) {
- $res = $this->dbConnection->select(
- $propertyTable->getName(),
- 'COUNT(DISTINCT(p_id)) AS count',
- array(),
- __METHOD__
- );
- $row = $this->dbConnection->fetchObject( $res );
- $count += $row->count;
- } else {
- $res = $this->dbConnection->select(
- $propertyTable->getName(),
- '*',
- array(),
- __METHOD__,
- array( 'LIMIT' => 1 )
- );
+ $row = $this->dbConnection->selectRow(
+ array( $this->store->getStatisticsTable() ),
+ 'Count( * ) AS count',
+ array( 'usage_count > 0' ),
+ __METHOD__
+ );
- if ( $this->dbConnection->numRows( $res ) > 0 )
{
- $count++;
- }
- }
- }
+ $count = $row ? $row->count : $count;
wfProfileOut( __METHOD__ );
return (int)$count;
diff --git
a/tests/phpunit/includes/storage/sqlstore/StatisticsCollectorTest.php
b/tests/phpunit/includes/storage/sqlstore/StatisticsCollectorTest.php
index 36539ae..8f09aad 100644
--- a/tests/phpunit/includes/storage/sqlstore/StatisticsCollectorTest.php
+++ b/tests/phpunit/includes/storage/sqlstore/StatisticsCollectorTest.php
@@ -49,14 +49,14 @@
*
* @return StatisticsCollector
*/
- private function newInstance( $count = 1, $cacheEnabled = false ) {
+ private function newInstance( $count = 1, $cacheEnabled = false, $hash
= 'foo' ) {
// $store = $this->newMockObject( array( 'getPropertyTables' =>
array( 'smw_test' ) ) )->getMockStore();
$store = StoreFactory::getStore();
$result = array(
'count' => $count,
- 'o_hash' => 'foo'
+ 'o_hash' => $hash
);
$resultWrapper = new FakeResultWrapper( array( (object)$result
) );
@@ -72,6 +72,10 @@
->will( $this->returnValue( $resultWrapper ) );
$connection->expects( $this->any() )
+ ->method( 'selectRow' )
+ ->will( $this->returnValue( $resultWrapper ) );
+
+ $connection->expects( $this->any() )
->method( 'fetchObject' )
->will( $this->returnValue( $resultWrapper ) );
@@ -80,8 +84,7 @@
->will( $this->returnValue( $count ) );
// Settings to be used
- // hash = HashBagOStuff is used for testing only
- $settings = Settings::newFromArray( array(
+ $settings = $this->newSettings( array(
'smwgCacheType' => 'hash',
'smwgStatisticsCache' => $cacheEnabled,
'smwgStatisticsCacheExpiry' => 3600
@@ -123,12 +126,22 @@
* @dataProvider getFunctionDataProvider
*
* @since 1.9
+ *
+ * @param $function
+ * @param $expectedType
*/
public function testFunctions( $function, $expectedType ) {
- $instance = $this->newInstance();
+
+ $count = rand();
+ $hash = 'Quxxey';
+ $expectedCount = $expectedType === 'array' ? array( $hash =>
$count ) : $count;
+
+ $instance = $this->newInstance( $count, false, $hash );
+
$result = call_user_func( array( &$instance, $function ) );
$this->assertInternalType( $expectedType, $result );
+ $this->assertEquals( $expectedCount, $result );
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/69668
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3966cae3efe3b9dc64b1f89b4c818430dbea5348
Gerrit-PatchSet: 14
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Nischayn22 <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Markus Kroetzsch <[email protected]>
Gerrit-Reviewer: Mwjames <[email protected]>
Gerrit-Reviewer: Nischayn22 <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits