Skip to content

Commit

Permalink
Refs #3906
Browse files Browse the repository at this point in the history
 * Speeding up the suggestion list by only requesting actions when they are really needed
  • Loading branch information
mattab committed Apr 20, 2013
1 parent 0474842 commit ea240af
Show file tree
Hide file tree
Showing 2 changed files with 254 additions and 214 deletions.
23 changes: 18 additions & 5 deletions plugins/API/API.php
Expand Up @@ -1650,18 +1650,31 @@ public function getSuggestedValuesForSegment($segmentName, $idSite)
throw new Exception("Requested segment not found.");
}

$startDate = Piwik_Date::now()->subDay(60)->toString();
$segmentsNeedActionsInfo = array('visitConvertedGoalId',
'pageUrl', 'pageTitle', 'siteSearchKeyword',
'entryPageTitle', 'entryPageUrl', 'exitPageTitle', 'exitPageUrl');
$isCustomVariablePage = stripos($segmentName, 'customVariablePage') !== false;
$doesSegmentNeedActionsInfo = in_array($segmentName, $segmentsNeedActionsInfo) || $isCustomVariablePage;

// we know which SQL field this segment matches to: call the LIVE api to get last 1000 visitors values
$request = new Piwik_API_Request("method=Live.getLastVisitsDetails
$startDate = Piwik_Date::now()->subDay(60)->toString();
$requestLastVisits = "method=Live.getLastVisitsDetails
&idSite=$idSite
&period=range
&date=$startDate,today
&filter_limit=10000
&format=original
&serialize=0
&flat=1
&segment=");
&segment=";

// By default Live fetches all actions for all visitors, but we'd rather do this only when required
if(!$doesSegmentNeedActionsInfo) {
$requestLastVisits .= "&doNotFetchActions=1";
$requestLastVisits .= "&filter_limit=10000";
} else {
$requestLastVisits .= "&filter_limit=1000";
}

$request = new Piwik_API_Request($requestLastVisits);
$table = $request->process();
if(empty($table)) {
throw new Exception("There was no data to suggest for $segmentName");
Expand Down

0 comments on commit ea240af

Please sign in to comment.