Skip to content
Extraits de code Groupes Projets
Valider f31a8c83 rédigé par Thomas Steur's avatar Thomas Steur
Parcourir les fichiers

a view more performance improvements, especially to reduce Piwik::translate() calls

parent b76d9b34
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -35,11 +35,7 @@ class StaticCache ...@@ -35,11 +35,7 @@ class StaticCache
public function get() public function get()
{ {
if (self::has()) { return self::$staticCache[$this->cacheKey];
return self::$staticCache[$this->cacheKey];
}
return null;
} }
public function has() public function has()
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
namespace Piwik; namespace Piwik;
use Piwik\Cache\LanguageAwareStaticCache;
use Piwik\Cache\PluginAwareStaticCache; use Piwik\Cache\PluginAwareStaticCache;
require_once PIWIK_INCLUDE_PATH . "/core/Piwik.php"; require_once PIWIK_INCLUDE_PATH . "/core/Piwik.php";
...@@ -279,17 +280,32 @@ class Metrics ...@@ -279,17 +280,32 @@ class Metrics
static public function getDefaultMetrics() static public function getDefaultMetrics()
{ {
$cache = new LanguageAwareStaticCache('DefaultMetrics');
if ($cache->has()) {
return $cache->get();
}
$translations = array( $translations = array(
'nb_visits' => 'General_ColumnNbVisits', 'nb_visits' => 'General_ColumnNbVisits',
'nb_uniq_visitors' => 'General_ColumnNbUniqVisitors', 'nb_uniq_visitors' => 'General_ColumnNbUniqVisitors',
'nb_actions' => 'General_ColumnNbActions', 'nb_actions' => 'General_ColumnNbActions',
); );
$translations = array_map(array('\\Piwik\\Piwik','translate'), $translations); $translations = array_map(array('\\Piwik\\Piwik','translate'), $translations);
$cache->set($translations);
return $translations; return $translations;
} }
static public function getDefaultProcessedMetrics() static public function getDefaultProcessedMetrics()
{ {
$cache = new LanguageAwareStaticCache('DefaultProcessedMetrics');
if ($cache->has()) {
return $cache->get();
}
$translations = array( $translations = array(
// Processed in AddColumnsProcessedMetrics // Processed in AddColumnsProcessedMetrics
'nb_actions_per_visit' => 'General_ColumnActionsPerVisit', 'nb_actions_per_visit' => 'General_ColumnActionsPerVisit',
...@@ -297,7 +313,11 @@ class Metrics ...@@ -297,7 +313,11 @@ class Metrics
'bounce_rate' => 'General_ColumnBounceRate', 'bounce_rate' => 'General_ColumnBounceRate',
'conversion_rate' => 'General_ColumnConversionRate', 'conversion_rate' => 'General_ColumnConversionRate',
); );
return array_map(array('\\Piwik\\Piwik','translate'), $translations); $translations = array_map(array('\\Piwik\\Piwik','translate'), $translations);
$cache->set($translations);
return $translations;
} }
static public function getReadableColumnName($columnIdRaw) static public function getReadableColumnName($columnIdRaw)
......
...@@ -32,12 +32,26 @@ class Report ...@@ -32,12 +32,26 @@ class Report
protected $widgetTitle; protected $widgetTitle;
protected $widgetParams = array(); protected $widgetParams = array();
protected $menuTitle; protected $menuTitle;
protected $processedMetrics = array(); protected $processedMetrics = null;
protected $hasGoalMetrics = false; protected $hasGoalMetrics = false;
protected $metrics = array(); protected $metrics = array();
protected $constantRowsCount = null; protected $constantRowsCount = null;
protected $isSubtableReport = null; protected $isSubtableReport = null;
protected $parameters = null; protected $parameters = null;
private static $orderOfReports = array(
'General_MultiSitesSummary',
'VisitsSummary_VisitsSummary',
'Goals_Ecommerce',
'General_Actions',
'Events_Events',
'Actions_SubmenuSitesearch',
'Referrers_Referrers',
'Goals_Goals',
'General_Visitors',
'DevicesDetection_DevicesDetection',
'UserSettings_VisitorSettings',
);
/** /**
* @var \Piwik\Plugin\VisitDimension|\Piwik\Plugin\ActionDimension * @var \Piwik\Plugin\VisitDimension|\Piwik\Plugin\ActionDimension
...@@ -58,7 +72,7 @@ class Report ...@@ -58,7 +72,7 @@ class Report
$this->module = $parts[2]; $this->module = $parts[2];
$this->action = lcfirst($parts[4]); $this->action = lcfirst($parts[4]);
$this->processedMetrics = Metrics::getDefaultProcessedMetrics(); $this->processedMetrics = Metrics::getDefaultProcessedMetrics();
$this->metrics = array_keys(Metrics::getDefaultMetrics()); $this->metrics = array_keys(Metrics::getDefaultMetrics());
$this->init(); $this->init();
} }
...@@ -196,7 +210,8 @@ class Report ...@@ -196,7 +210,8 @@ class Report
$report['metrics'] = $this->getMetrics(); $report['metrics'] = $this->getMetrics();
$report['metricsDocumentation'] = $this->getMetricsDocumentation(); $report['metricsDocumentation'] = $this->getMetricsDocumentation();
$report['processedMetrics'] = $this->processedMetrics;
$report['processedMetrics'] = $this->processedMetrics;
if (!empty($this->actionToLoadSubTables)) { if (!empty($this->actionToLoadSubTables)) {
$report['actionToLoadSubTables'] = $this->actionToLoadSubTables; $report['actionToLoadSubTables'] = $this->actionToLoadSubTables;
...@@ -297,37 +312,14 @@ class Report ...@@ -297,37 +312,14 @@ class Report
* API metadata are sorted by category/name, * API metadata are sorted by category/name,
* with a little tweak to replicate the standard Piwik category ordering * with a little tweak to replicate the standard Piwik category ordering
* *
* @param array|Report $a * @param Report $a
* @param array|Report $b * @param Report $b
* @return int * @return int
*/ */
public static function sort($a, $b) public static function sort($a, $b)
{ {
static $order = null; return ($category = strcmp(array_search($a->category, self::$orderOfReports), array_search($b->category, self::$orderOfReports))) == 0
if (is_null($order)) { ? ($a->order < $b->order ? -1 : 1)
$order = array(
Piwik::translate('General_MultiSitesSummary'),
Piwik::translate('VisitsSummary_VisitsSummary'),
Piwik::translate('Goals_Ecommerce'),
Piwik::translate('General_Actions'),
Piwik::translate('Events_Events'),
Piwik::translate('Actions_SubmenuSitesearch'),
Piwik::translate('Referrers_Referrers'),
Piwik::translate('Goals_Goals'),
Piwik::translate('General_Visitors'),
Piwik::translate('DevicesDetection_DevicesDetection'),
Piwik::translate('UserSettings_VisitorSettings'),
);
}
$catA = is_object($a) ? $a->category : $a['category'];
$catB = is_object($b) ? $b->category : $b['category'];
$orderA = is_object($a) ? $a->order : @$a['order'];
$orderB = is_object($b) ? $b->order : @$b['order'];
return ($category = strcmp(array_search($catA, $order), array_search($catB, $order))) == 0
? ($orderA < $orderB ? -1 : 1)
: $category; : $category;
} }
......
...@@ -245,9 +245,6 @@ class ProcessedReport ...@@ -245,9 +245,6 @@ class ProcessedReport
*/ */
Piwik::postEvent('API.getReportMetadata.end', array(&$availableReports, $parameters)); Piwik::postEvent('API.getReportMetadata.end', array(&$availableReports, $parameters));
// Sort results to ensure consistent order
usort($availableReports, array('\Piwik\Plugin\Report', 'sort'));
// Add the magic API.get report metadata aggregating all plugins API.get API calls automatically // Add the magic API.get report metadata aggregating all plugins API.get API calls automatically
$this->addApiGetMetdata($availableReports); $this->addApiGetMetdata($availableReports);
......
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