Skip to content
Extraits de code Groupes Projets
Valider 22587013 rédigé par Matthieu Aubry's avatar Matthieu Aubry
Parcourir les fichiers

Merge pull request #10024 from piwik/9200

Live API when a Segment is used: Select 10 times more rows so that resultset after grouping is more likely to contain enough rows
parents ffc44c79 0cdb6ef9
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -408,17 +408,28 @@ class Model
$orderBy .= "visit_last_action_time " . $filterSortOrder;
$orderByParent = "sub.visit_last_action_time " . $filterSortOrder;
$subQuery = $segment->getSelectQuery($select, $from, $where, $whereBind, $orderBy, $groupBy, $limit, $offset);
// this $innerLimit is a workaround (see https://github.com/piwik/piwik/issues/9200#issuecomment-183641293)
$innerLimit = $limit;
if (!$segment->isEmpty()) {
$innerLimit = $limit * 10;
}
$innerQuery = $segment->getSelectQuery($select, $from, $where, $whereBind, $orderBy, $groupBy, $innerLimit, $offset);
$bind = $subQuery['bind'];
// Group by idvisit so that a visitor converting 2 goals only appears once
$bind = $innerQuery['bind'];
// Group by idvisit so that a given visit appears only once, useful when for example:
// 1) when a visitor converts 2 goals
// 2) when an Action Segment is used, the inner query will return one row per action, but we want one row per visit
$sql = "
SELECT sub.* FROM (
" . $subQuery['sql'] . "
" . $innerQuery['sql'] . "
) AS sub
GROUP BY sub.idvisit
ORDER BY $orderByParent
";
if($limit) {
$sql .= sprintf("LIMIT %d \n", $limit);
}
return array($sql, $bind);
}
......
......@@ -57,6 +57,7 @@ class ModelTest extends IntegrationTestCase
) AS sub
GROUP BY sub.idvisit
ORDER BY sub.visit_last_action_time DESC
LIMIT 100
';
$expectedBind = array(
'1',
......@@ -97,6 +98,7 @@ class ModelTest extends IntegrationTestCase
) AS sub
GROUP BY sub.idvisit
ORDER BY sub.visit_last_action_time DESC
LIMIT 100
';
$expectedBind = array(
'2',
......@@ -135,6 +137,7 @@ class ModelTest extends IntegrationTestCase
) AS sub
GROUP BY sub.idvisit
ORDER BY sub.visit_last_action_time DESC
LIMIT 100
';
$expectedBind = array(
'1',
......@@ -175,12 +178,13 @@ class ModelTest extends IntegrationTestCase
AND log_visit.visit_last_action_time <= ? )
AND ( log_link_visit_action.custom_var_k1 = ? )
ORDER BY idsite, visit_last_action_time DESC
LIMIT 10, 100
LIMIT 10, 1000
) AS log_inner
ORDER BY idsite, visit_last_action_time DESC
) AS sub
GROUP BY sub.idvisit
ORDER BY sub.visit_last_action_time DESC
LIMIT 100
';
$expectedBind = array(
'1',
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter