Skip to content

Commit 09ec671

Browse files
author
Prabhu Ram
committed
MC-19115: Admin Analytics tracking should be enabled by default
- Added caching in product metadata to improve performance
1 parent d41fc7b commit 09ec671

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

lib/internal/Magento/Framework/App/ProductMetadata.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class ProductMetadata implements ProductMetadataInterface
2828
*/
2929
const PRODUCT_NAME = 'Magento';
3030

31+
/**
32+
* Magento version cache prefix
33+
*/
34+
const CACHE_PREFIX = 'mage-version';
35+
3136
/**
3237
* Product version
3338
*
@@ -47,11 +52,21 @@ class ProductMetadata implements ProductMetadataInterface
4752
private $composerInformation;
4853

4954
/**
55+
* @var CacheInterface
56+
*/
57+
private $cache;
58+
59+
/**
60+
* ProductMetadata constructor.
5061
* @param ComposerJsonFinder $composerJsonFinder
62+
* @param \Magento\Framework\App\CacheInterface $cache
5163
*/
52-
public function __construct(ComposerJsonFinder $composerJsonFinder)
53-
{
64+
public function __construct(
65+
ComposerJsonFinder $composerJsonFinder,
66+
CacheInterface $cache = null
67+
) {
5468
$this->composerJsonFinder = $composerJsonFinder;
69+
$this->cache = $cache ?? ObjectManager::getInstance()->get(CacheInterface::class);
5570
}
5671

5772
/**
@@ -61,13 +76,16 @@ public function __construct(ComposerJsonFinder $composerJsonFinder)
6176
*/
6277
public function getVersion()
6378
{
79+
$versionFromCache = $this->cache->load(self::CACHE_PREFIX);
80+
$this->version = $this->version ?: $versionFromCache;
6481
if (!$this->version) {
6582
if (!($this->version = $this->getSystemPackageVersion())) {
6683
if ($this->getComposerInformation()->isMagentoRoot()) {
6784
$this->version = $this->getComposerInformation()->getRootPackage()->getPrettyVersion();
6885
} else {
6986
$this->version = 'UNKNOWN';
7087
}
88+
$this->cache->save($this->version, self::CACHE_PREFIX, [Config::CACHE_TAG]);
7189
}
7290
}
7391
return $this->version;

0 commit comments

Comments
 (0)