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:
authorsgiehl <stefan@piwik.org>2014-05-31 22:50:25 +0400
committersgiehl <stefan@piwik.org>2014-05-31 22:50:25 +0400
commit0d7b51944e9b1c18859dcb99ed6397859ca17e07 (patch)
tree7a4c71e3ab1078848436f1382b21c63de8977fde
parenteaf1036670082fcedeae42d03624c9312a5db271 (diff)
added special DeviceDetectorCache class used for caching DeviceDetector. This cache combines file and static caching to speed up detections as much as possible
-rw-r--r--core/CacheFile.php2
-rw-r--r--core/DeviceDetectorCache.php65
-rw-r--r--core/Tracker/Settings.php4
-rw-r--r--core/Tracker/Visit.php1
-rw-r--r--piwik.php3
-rw-r--r--plugins/DevicesDetection/DevicesDetection.php4
6 files changed, 70 insertions, 9 deletions
diff --git a/core/CacheFile.php b/core/CacheFile.php
index f75657f176..5d9000332f 100644
--- a/core/CacheFile.php
+++ b/core/CacheFile.php
@@ -16,7 +16,7 @@ use Exception;
* It is for example used by the Tracker process to cache various settings and websites attributes in tmp/cache/tracker/*
*
*/
-class CacheFile implements \DeviceDetector\Cache\CacheInterface
+class CacheFile
{
// for testing purposes since tests run on both CLI/FPM (changes in CLI can't invalidate
// opcache in FPM, so we have to invalidate before reading)
diff --git a/core/DeviceDetectorCache.php b/core/DeviceDetectorCache.php
new file mode 100644
index 0000000000..744560df92
--- /dev/null
+++ b/core/DeviceDetectorCache.php
@@ -0,0 +1,65 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+namespace Piwik;
+
+use Exception;
+
+/**
+ * Caching class used for DeviceDetector caching
+ *
+ * Combines Piwik\CacheFile with an additional caching in static property
+ *
+ * Static caching speeds up multiple detections in one request, which is mostly the case when importing logs
+ */
+class DeviceDetectorCache extends CacheFile implements \DeviceDetector\Cache\CacheInterface
+{
+ protected static $staticCache = array();
+
+ /**
+ * Function to fetch a cache entry
+ *
+ * @param string $id The cache entry ID
+ * @return array|bool False on error, or array the cache content
+ */
+ public function get($id)
+ {
+ if (empty($id)) {
+ return false;
+ }
+ $id = $this->cleanupId($id);
+
+ if (array_key_exists($id, self::$staticCache)) {
+ return self::$staticCache[$id];
+ }
+
+ return parent::get($id);
+ }
+
+
+ /**
+ * A function to store content a cache entry.
+ *
+ * @param string $id The cache entry ID
+ * @param array $content The cache content
+ * @throws \Exception
+ * @return bool True if the entry was succesfully stored
+ */
+ public function set($id, $content)
+ {
+ if (empty($id)) {
+ return false;
+ }
+
+ $id = $this->cleanupId($id);
+
+ self::$staticCache[$id] = $content;
+
+ return parent::set($id, $content);
+ }
+}
diff --git a/core/Tracker/Settings.php b/core/Tracker/Settings.php
index 251046ca29..8aa5b9a0df 100644
--- a/core/Tracker/Settings.php
+++ b/core/Tracker/Settings.php
@@ -8,7 +8,7 @@
*/
namespace Piwik\Tracker;
-use Piwik\CacheFile;
+use Piwik\DeviceDetectorCache;
use Piwik\Tracker;
use DeviceDetector\DeviceDetector;
@@ -39,7 +39,7 @@ class Settings
$deviceDetector = new DeviceDetector($userAgent);
$deviceDetector->discardBotInformation();
- $deviceDetector->setCache(new CacheFile('tracker', 86400));
+ $deviceDetector->setCache(new DeviceDetectorCache('tracker', 86400));
$deviceDetector->parse();
$aBrowserInfo = $deviceDetector->getClient();
diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php
index 75a11e128a..643c6bf31b 100644
--- a/core/Tracker/Visit.php
+++ b/core/Tracker/Visit.php
@@ -9,7 +9,6 @@
namespace Piwik\Tracker;
-use DeviceDetector\DeviceDetector;
use Piwik\Common;
use Piwik\Config;
use Piwik\IP;
diff --git a/piwik.php b/piwik.php
index 03e405cdd9..2552867936 100644
--- a/piwik.php
+++ b/piwik.php
@@ -40,9 +40,6 @@ if (!defined('PIWIK_INCLUDE_PATH')) {
@ignore_user_abort(true);
-/*
- * Manually require needed vendor libraries, as composers autorequire would do too much
- */
if (file_exists(PIWIK_INCLUDE_PATH . '/vendor/autoload.php')) {
$vendorDirectory = PIWIK_INCLUDE_PATH . '/vendor';
} else {
diff --git a/plugins/DevicesDetection/DevicesDetection.php b/plugins/DevicesDetection/DevicesDetection.php
index dc915e359f..c6c9262f05 100644
--- a/plugins/DevicesDetection/DevicesDetection.php
+++ b/plugins/DevicesDetection/DevicesDetection.php
@@ -13,9 +13,9 @@ use DeviceDetector\Parser\Device\DeviceParserAbstract AS DeviceParser;
use DeviceDetector\DeviceDetector;
use Exception;
use Piwik\ArchiveProcessor;
-use Piwik\CacheFile;
use Piwik\Common;
use Piwik\Db;
+use Piwik\DeviceDetectorCache;
use Piwik\Piwik;
use Piwik\Plugin\ViewDataTable;
use Piwik\WidgetsList;
@@ -245,7 +245,7 @@ class DevicesDetection extends \Piwik\Plugin
$UAParser = new DeviceDetector($userAgent);
$UAParser->discardBotInformation();
- $UAParser->setCache(new CacheFile('tracker', 86400));
+ $UAParser->setCache(new DeviceDetectorCache('tracker', 86400));
$UAParser->parse();
$deviceInfo['config_browser_name'] = $UAParser->getClient("type") == 'browser' ? $UAParser->getClient("short_name") : 'UNK';
$deviceInfo['config_browser_version'] = $UAParser->getClient("type") == 'browser' ? $UAParser->getClient("version") : 'UNK';