Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Aubry <matt@piwik.org>2016-04-11 03:26:27 +0300
committerMatthieu Aubry <matt@piwik.org>2016-04-11 03:26:27 +0300
commit225870137b423c6a330f78003717a234c3908176 (patch)
treea1dab94d0846f05a859f1dfffb6fcf71c94c2cf5 /plugins
parentffc44c7973a6a3ab357e5bf354e7c0f2f37d6b41 (diff)
parent0cdb6ef966754e654fbeb95ccc09e6a281f9802c (diff)
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
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Live/Model.php19
-rw-r--r--plugins/Live/tests/Integration/ModelTest.php6
2 files changed, 20 insertions, 5 deletions
diff --git a/plugins/Live/Model.php b/plugins/Live/Model.php
index 276061e14d..80b0c42c9c 100644
--- a/plugins/Live/Model.php
+++ b/plugins/Live/Model.php
@@ -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);
}
diff --git a/plugins/Live/tests/Integration/ModelTest.php b/plugins/Live/tests/Integration/ModelTest.php
index 828d3865f0..3002b847ba 100644
--- a/plugins/Live/tests/Integration/ModelTest.php
+++ b/plugins/Live/tests/Integration/ModelTest.php
@@ -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',