Skip to content

Commit

Permalink
Fixes #3482, apply quick fix so Piwik works when ranking query is dis…
Browse files Browse the repository at this point in the history
…abled and added test for disabled ranking query. Added FIXME comment to make sure underlying issue is eventually dealt with.
  • Loading branch information
diosmosis committed Apr 13, 2013
1 parent e6b6d8a commit 4b4277b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
27 changes: 27 additions & 0 deletions plugins/Actions/Archiving.php
Expand Up @@ -106,6 +106,33 @@ public function archivePeriod(Piwik_ArchiveProcessing_Period $archiveProcessing)
public function archiveDay(Piwik_ArchiveProcessing $archiveProcessing)
{
$rankingQueryLimit = self::getRankingQueryLimit();

// FIXME: This is a quick fix for #3482. The actual cause of the bug is that
// the site search & performance metrics additions to
// Piwik_Actions_ArchivingHelper::updateActionsTableWithRowQuery expect every
// row to have 'type' data, but not all of the SQL queries that are run w/o
// ranking query join on the log_action table and thus do not select the
// log_action.type column.
//
// NOTES: Archiving logic can be generalized as follows:
// 0) Do SQL query over log_link_visit_action & join on log_action to select
// some metrics (like visits, hits, etc.)
// 1) For each row, cache the action row & metrics. (This is done by
// updateActionsTableWithRowQuery for result set rows that have
// name & type columns.)
// 2) Do other SQL queries for metrics we can't put in the first query (like
// entry visits, exit vists, etc.) w/o joining log_action.
// 3) For each row, find the cached row by idaction & add the new metrics to
// it. (This is done by updateActionsTableWithRowQuery for result set rows
// that DO NOT have name & type columns.)
//
// The site search & performance metrics additions expect a 'type' all the time
// which breaks the original pre-rankingquery logic. Ranking query requires a
// join, so the bug is only seen when ranking query is disabled.
if ($rankingQueryLimit === 0) {
$rankingQueryLimit = 100000;
}

Piwik_Actions_ArchivingHelper::reloadConfig();

$this->initActionsTables();
Expand Down
2 changes: 2 additions & 0 deletions plugins/Actions/ArchivingHelper.php
Expand Up @@ -22,6 +22,8 @@ class Piwik_Actions_ArchivingHelper
const OTHERS_ROW_KEY = '';

/**
* FIXME See FIXME related to this function at Piwik_Actions_Archiving::archiveDay.
*
* @param Zend_Db_Statement|PDOStatement $query
* @param string|bool $fieldQueried
* @param array $actionsTablesByType
Expand Down
32 changes: 32 additions & 0 deletions tests/PHPUnit/Integration/BlobReportLimitingTest.php
Expand Up @@ -48,6 +48,15 @@ public function getApiForTesting()
'periods' => 'day')),
);
}

public function getRankingQueryDisabledApiForTesting()
{
return array(
array('Actions.getPageUrls', array('idSite' => self::$fixture->idSite,
'date' => self::$fixture->dateTime,
'periods' => array('day'))),
);
}

/**
* @dataProvider getApiForTesting
Expand Down Expand Up @@ -82,6 +91,29 @@ public function testApiWithRankingQuery()
$this->runApiTests($apiToCall, $params);
}
}

/**
* @group Integration
* @group BlobReportLimiting
*/
public function testApiWithRankingQueryDisabled()
{
self::deleteArchiveTables();
$generalConfig =& Piwik_Config::getInstance()->General;
$generalConfig['datatable_archiving_maximum_rows_referers'] = 500;
$generalConfig['datatable_archiving_maximum_rows_subtable_referers'] = 500;
$generalConfig['datatable_archiving_maximum_rows_actions'] = 500;
$generalConfig['datatable_archiving_maximum_rows_subtable_actions'] = 500;
$generalConfig['datatable_archiving_maximum_rows_standard'] = 500;
$generalConfig['archiving_ranking_query_row_limit'] = 0;

foreach ($this->getRankingQueryDisabledApiForTesting() as $pair) {
list($apiToCall, $params) = $pair;
$params['testSuffix'] = '_rankingQueryDisabled';

$this->runApiTests($apiToCall, $params);
}
}

public function getOutputPrefix()
{
Expand Down

0 comments on commit 4b4277b

Please sign in to comment.