diff options
-rw-r--r-- | config/global.ini.php | 15 | ||||
-rw-r--r-- | core/ArchiveProcessing/Period.php | 6 | ||||
-rw-r--r-- | core/Controller.php | 3 | ||||
-rw-r--r-- | core/Piwik.php | 39 | ||||
-rw-r--r-- | plugins/API/API.php | 2 | ||||
-rw-r--r-- | plugins/MultiSites/templates/index.tpl | 4 | ||||
-rw-r--r-- | plugins/MultiSites/templates/row.tpl | 4 | ||||
-rw-r--r-- | plugins/VisitsSummary/templates/sparklines.tpl | 2 | ||||
-rw-r--r-- | tests/core/PHP_Related.test.php | 4 |
9 files changed, 47 insertions, 32 deletions
diff --git a/config/global.ini.php b/config/global.ini.php index db90eea149..423b107f30 100644 --- a/config/global.ini.php +++ b/config/global.ini.php @@ -47,6 +47,7 @@ always_archive_data_range = 0; ; if set to 1, all the SQL queries will be recorded by the profiler ; and a profiling summary will be printed at the end of the request +; NOTE: you must also set [log]logger_message[] = "screen" to enable the profiler to print on screen enable_sql_profiler = 0 ; if set to 1, a Piwik tracking code will be included in the Piwik UI footer and will track visits, pages, etc. to idsite = 1 @@ -66,6 +67,11 @@ disable_merged_requests = 0 tracker_always_new_visitor = 0 [General] +; if set to 1, Unique Visitors will be processed for Years and Date Ranges +; disabled by default, to ensure optimal performance for high traffic Piwik instances +; if you set it to 1 and want the Unique Visitors to be re-processed in for reports in the past, drop all piwik_archive_* tables +enable_processing_unique_visitors_year_and_range = 0 + ; when set to 1, all requests to Piwik will return a maintenance message without connecting to the DB ; this is useful when upgrading using the shell command, to prevent other users from accessing the UI while Upgrade is in progress maintenance_mode = 0 @@ -118,9 +124,10 @@ default_day = yesterday ; Possible values: day, week, month, year. default_period = day -; This setting is overriden in the UI, under "General Settings". This is the default value used if the setting hasn't been overriden via the UI. ; Time in seconds after which an archive will be computed again. This setting is used only for today's statistics. ; Defaults to 10 seconds so that by default, Piwik provides real time reporting. +; This setting is overriden in the UI, under "General Settings". +; This is the default value used if the setting hasn't been overriden via the UI. time_before_today_archive_considered_outdated = 10 ; This setting is overriden in the UI, under "General Settings". The default value is to allow browsers @@ -254,7 +261,8 @@ cookie_path = ; set to 0 if you want to stop tracking the visitors. Useful if you need to stop all the connections on the DB. record_statistics = 1 -; length of a visit in seconds. If a visitor comes back on the website visit_standard_length seconds after his last page view, it will be recorded as a new visit +; length of a visit in seconds. If a visitor comes back on the website visit_standard_length seconds +; after his last page view, it will be recorded as a new visit visit_standard_length = 1800 ; visitors that stay on the website and view only one page will be considered as time on site of 0 second @@ -286,7 +294,8 @@ ignore_visits_cookie_name = piwik_ignore campaign_var_name = piwik_campaign ; variable name to track any campaign keyword -; Example: If a visitor first visits 'index.php?piwik_campaign=Adwords-CPC&piwik_kwd=My killer keyword' then it will be counted as a campaign referer named 'Adwords-CPC' with the keyword 'My killer keyword' +; Example: If a visitor first visits 'index.php?piwik_campaign=Adwords-CPC&piwik_kwd=My killer keyword' ; +; then it will be counted as a campaign referer named 'Adwords-CPC' with the keyword 'My killer keyword' campaign_keyword_var_name = piwik_kwd ; maximum length of a Page Title or a Page URL recorded in the log_action.name table diff --git a/core/ArchiveProcessing/Period.php b/core/ArchiveProcessing/Period.php index 47e29255b6..81202aa2cd 100644 --- a/core/ArchiveProcessing/Period.php +++ b/core/ArchiveProcessing/Period.php @@ -112,12 +112,13 @@ class Piwik_ArchiveProcessing_Period extends Piwik_ArchiveProcessing // build the Record Numeric objects $records = array(); + + $shouldProcessUniqueVisitors = Piwik::isUniqueVisitorsEnabled($this->period->getLabel()); foreach($results as $name => $value) { if($name == 'nb_uniq_visitors') { - // we do not process Unique Visitors for year - if($this->periodId == Piwik::$idPeriods['year']) + if(!$shouldProcessUniqueVisitors) { continue; } @@ -140,7 +141,6 @@ class Piwik_ArchiveProcessing_Period extends Piwik_ArchiveProcessing return $records; } - /** * This method will compute the sum of DataTables over the period for the given fields $aRecordName. * The resulting DataTable will be then added to queue of data to be recorded in the database. diff --git a/core/Controller.php b/core/Controller.php index 21cca06c10..437fc49d29 100644 --- a/core/Controller.php +++ b/core/Controller.php @@ -319,6 +319,8 @@ abstract class Piwik_Controller $this->setPeriodVariablesView($view); $periodStr = Piwik_Common::getRequestVar('period'); + $view->displayUniqueVisitors = Piwik::isUniqueVisitorsEnabled($periodStr); + $rawDate = Piwik_Common::getRequestVar('date'); if($periodStr!='range') { @@ -354,6 +356,7 @@ abstract class Piwik_Controller $view->startDate = $dateStart; $view->endDate = $dateEnd; + $this->setBasicVariablesView($view); } catch(Exception $e) { //TODO here display std error message rather than redirect diff --git a/core/Piwik.php b/core/Piwik.php index 1f8669ce46..5f09362d28 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -34,6 +34,19 @@ class Piwik 'range' => 5, ); + /** + * Should we process and display Unique Visitors? + * -> Always process for day/week/month periods + * For Year and Range, only process if it was enabled in the config file, + * + * @return bool + */ + static public function isUniqueVisitorsEnabled($periodLabel) + { + return in_array($periodLabel, array('day', 'week', 'month')) + || Zend_Registry::get('config')->General->enable_processing_unique_visitors_year_and_range ; + } + /* * Prefix/unprefix class name */ @@ -997,8 +1010,7 @@ class Piwik } uasort( $infoIndexedByQuery, 'sortTimeDesc'); - Piwik::log('<hr /><b>SQL Profiler</b>'); - Piwik::log('<hr /><b>Summary</b>'); + $str = '<hr /><b>SQL Profiler</b><hr /><b>Summary</b><br/>'; $totalTime = $profiler->getTotalElapsedSecs(); $queryCount = $profiler->getTotalNumQueries(); $longestTime = 0; @@ -1009,7 +1021,7 @@ class Piwik $longestQuery = $query->getQuery(); } } - $str = 'Executed ' . $queryCount . ' queries in ' . round($totalTime,3) . ' seconds' . "\n"; + $str .= 'Executed ' . $queryCount . ' queries in ' . round($totalTime,3) . ' seconds' . "\n"; $str .= '(Average query length: ' . round($totalTime / $queryCount,3) . ' seconds)' . "\n"; $str .= '<br />Queries per second: ' . round($queryCount / $totalTime,1) . "\n"; $str .= '<br />Longest query length: ' . round($longestTime,3) . " seconds (<code>$longestQuery</code>) \n"; @@ -1024,8 +1036,7 @@ class Piwik */ static private function getSqlProfilingQueryBreakdownOutput( $infoIndexedByQuery ) { - Piwik::log('<hr /><b>Breakdown by query</b>'); - $output = ''; + $output = '<hr /><b>Breakdown by query</b><br/>'; foreach($infoIndexedByQuery as $query => $queryInfo) { $timeMs = round($queryInfo['sumTimeMs'],1); @@ -1068,7 +1079,7 @@ class Piwik * * @param string $prefixString */ - static public function printMemoryUsage( $prefixString = null ) + static public function getMemoryUsage() { $memory = false; if(function_exists('xdebug_memory_usage')) @@ -1079,20 +1090,12 @@ class Piwik { $memory = memory_get_usage(); } - - if($memory !== false) - { - $usage = round( $memory / 1024 / 1024, 2); - if(!is_null($prefixString)) - { - Piwik::log($prefixString); - } - Piwik::log("Memory usage = $usage Mb"); - } - else + if($memory === false) { - Piwik::log("Memory usage function not found."); + return "Memory usage function not found."; } + $usage = number_format( round($memory / 1024 / 1024, 2), 2); + return "$usage Mb"; } /* diff --git a/plugins/API/API.php b/plugins/API/API.php index 574a5fb111..8b3f915f71 100644 --- a/plugins/API/API.php +++ b/plugins/API/API.php @@ -420,7 +420,7 @@ class Piwik_API_API ); // See ArchiveProcessing/Period.php - unique visitors are not processed for year period - if($period == 'year') + if(!Piwik::isUniqueVisitorsEnabled($period)) { unset($columns['nb_uniq_visitors']); unset($reportMetadata['metrics']['nb_uniq_visitors']); diff --git a/plugins/MultiSites/templates/index.tpl b/plugins/MultiSites/templates/index.tpl index ed37e187a3..fa602ade10 100644 --- a/plugins/MultiSites/templates/index.tpl +++ b/plugins/MultiSites/templates/index.tpl @@ -48,7 +48,7 @@ <span>{'General_ColumnPageviews'|translate}</span> <span class="arrow"></span> </th> - {if $period!='year'} + {if $displayUniqueVisitors} <th id="unique" class="multisites-column" style="width: 120px" onClick="params = setOrderBy(this,allSites, params, 'unique');"> <span>{'General_ColumnNbUniqVisitors'|translate}</span> <span class="arrow"></span> @@ -60,7 +60,7 @@ <select class="selector" id="evolution_selector" onchange="params['evolutionBy'] = $('#evolution_selector').val(); switchEvolution(params);"> <option value="visits" {if $evolutionBy eq 'visits'} selected {/if}>{'General_ColumnNbVisits'|translate}</option> <option value="actions" {if $evolutionBy eq 'actions'} selected {/if}>{'General_ColumnPageviews'|translate}</option> - {if $period!='year'}<option value="unique"{if $evolutionBy eq 'unique'} selected {/if}>{'General_ColumnNbUniqVisitors'|translate}</option> {/if} + {if $displayUniqueVisitors}<option value="unique"{if $evolutionBy eq 'unique'} selected {/if}>{'General_ColumnNbUniqVisitors'|translate}</option> {/if} </select> </th> </thead> diff --git a/plugins/MultiSites/templates/row.tpl b/plugins/MultiSites/templates/row.tpl index 25eb32142f..b2d80d4bff 100644 --- a/plugins/MultiSites/templates/row.tpl +++ b/plugins/MultiSites/templates/row.tpl @@ -11,7 +11,7 @@ <td class="multisites-column"> %actions% </td> -{if $period!='year'} +{if $displayUniqueVisitors} <td class="multisites-column"> %unique% </td> @@ -20,7 +20,7 @@ <td style="width:170px"> <div class="visits" style="display:none">%visitsSummary%</div> <div class="actions"style="display:none">%actionsSummary%</div> - {if $period!='year'} + {if $displayUniqueVisitors} <div class="unique" >%uniqueSummary%</div> {/if} </td> diff --git a/plugins/VisitsSummary/templates/sparklines.tpl b/plugins/VisitsSummary/templates/sparklines.tpl index 81dd2ca76d..dc230f3320 100644 --- a/plugins/VisitsSummary/templates/sparklines.tpl +++ b/plugins/VisitsSummary/templates/sparklines.tpl @@ -1,6 +1,6 @@ <div id='leftcolumn'> <div class="sparkline">{sparkline src=$urlSparklineNbVisits} {'VisitsSummary_NbVisits'|translate:"<strong>$nbVisits</strong>"}</div> -{if $period != 'year'} +{if $displayUniqueVisitors} <div class="sparkline">{sparkline src=$urlSparklineNbUniqVisitors} {'VisitsSummary_NbUniqueVisitors'|translate:"<strong>$nbUniqVisitors</strong>"}</div> {/if} <div class="sparkline">{sparkline src=$urlSparklineNbActions} {'VisitsSummary_NbActionsDescription'|translate:"<strong>$nbActions</strong>"}</div> diff --git a/tests/core/PHP_Related.test.php b/tests/core/PHP_Related.test.php index 29076ae226..59c23ac7d5 100644 --- a/tests/core/PHP_Related.test.php +++ b/tests/core/PHP_Related.test.php @@ -38,7 +38,7 @@ class Test_PHP_Related extends UnitTestCase // test array[0] array[100] array[200] // same memory usage? hash echo "start ". __FUNCTION__ . "<br>"; - Piwik::printMemoryUsage(); + echo Piwik::getMemoryUsage(); $timer = new Piwik_Timer(); $testId = 2; if($testId == 1) @@ -66,7 +66,7 @@ class Test_PHP_Related extends UnitTestCase } echo $timer . "<br>"; echo "size serialized:". Piwik::getPrettySizeFromBytes(strlen(serialize($array))). "<br>"; - Piwik::printMemoryUsage(); + echo Piwik::getMemoryUsage(); echo "end ". __FUNCTION__ . "<br>"; } |