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:
authorCyril Bonté <cyril.bonte@free.fr>2014-06-08 03:00:43 +0400
committerCyril Bonté <cyril.bonte@free.fr>2014-06-08 03:00:43 +0400
commit12b27e8701b2895b0daa87dbb4bacab5cc60147d (patch)
tree1a63d1acd4ac72d273eb59d18d3ed801031a7eba /core/Tracker/Settings.php
parentc65f56d740a56de624e83ffe32d0ce82aeb08f7f (diff)
cache parsed DeviceDetector instances for bulk requests
By caching parsed DeviceDetectors, we reduce the number of regexes to process. It allows to process more requests per second when the same user agent is met.
Diffstat (limited to 'core/Tracker/Settings.php')
-rw-r--r--core/Tracker/Settings.php16
1 files changed, 12 insertions, 4 deletions
diff --git a/core/Tracker/Settings.php b/core/Tracker/Settings.php
index 3e2a289e0a..8c8ff1a773 100644
--- a/core/Tracker/Settings.php
+++ b/core/Tracker/Settings.php
@@ -11,6 +11,7 @@ namespace Piwik\Tracker;
use Piwik\DeviceDetectorCache;
use Piwik\Tracker;
use DeviceDetector\DeviceDetector;
+use DeviceDetector\Cache\CacheStatic;
class Settings
{
@@ -37,10 +38,17 @@ class Settings
$resolution = $this->request->getParam('res');
$userAgent = $this->request->getUserAgent();
- $deviceDetector = new DeviceDetector($userAgent);
- $deviceDetector->discardBotInformation();
- $deviceDetector->setCache(new DeviceDetectorCache('tracker', 86400));
- $deviceDetector->parse();
+ static $deviceDetectorsCache;
+ $deviceDetectorsCache = new CacheStatic();
+ $deviceDetector = $deviceDetectorsCache->get($userAgent);
+ if (! $deviceDetector) {
+ $deviceDetector = new DeviceDetector($userAgent);
+ $deviceDetector->discardBotInformation();
+ $deviceDetector->setCache(new DeviceDetectorCache('tracker', 86400));
+ $deviceDetector->parse();
+
+ $deviceDetectorsCache->set($userAgent, $deviceDetector);
+ }
$aBrowserInfo = $deviceDetector->getClient();
if ($aBrowserInfo['type'] != 'browser') {