Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster unique visitors/users query #17827

Closed
wants to merge 1 commit into from
Closed

Faster unique visitors/users query #17827

wants to merge 1 commit into from

Conversation

tsteur
Copy link
Member

@tsteur tsteur commented Jul 28, 2021

refs #17750

@tsteur tsteur marked this pull request as draft July 28, 2021 04:39
@tsteur tsteur closed this Jul 29, 2021
@tsteur
Copy link
Member Author

tsteur commented Jul 29, 2021

Potential patch we could apply to only use this logic when cohorts is not enabled but then the tests etc everything becomes less testable ...

diff --git a/core/ArchiveProcessor.php b/core/ArchiveProcessor.php
index 9365152532..510c418f08 100644
--- a/core/ArchiveProcessor.php
+++ b/core/ArchiveProcessor.php
@@ -528,12 +528,20 @@ class ArchiveProcessor
     {
         $logAggregator = $this->getLogAggregator();
         $sitesBackup = $logAggregator->getSites();
-        $previous = $logAggregator->disallowUsageSegmentCache();
+
+        $hasCohorts = \Piwik\Plugin\Manager::getInstance()->isPluginActivated('Cohorts');
+        if (!$hasCohorts) {
+            // when cohorts is enabled, then it's better to create the segment table as cohorts will also issue a
+            // unique query on log data for weeks etc. This way the segment query is only executed once and in most
+            // cases things are faster that way. Vs when cohorts is disabled, then we don't want to first create a
+            // temporary segment table for the segment query and then execute the count.
+            $previous = $logAggregator->disallowUsageSegmentCache();
+        }
         $logAggregator->setSites($sites);
         try {
             $query = $logAggregator->queryVisitsByDimension(array(), false, array(), $metrics);
         } finally {
-            if ($previous) {
+            if (!empty($previous)) {
                 $logAggregator->allowUsageSegmentCache();
             }
             $logAggregator->setSites($sitesBackup);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant