Skip to content

Commit

Permalink
we do request the available view datatables many times, eg when detec…
Browse files Browse the repository at this point in the history
…ting the footerIcons. Instead cache the result to save many postEvents etc
  • Loading branch information
tsteur committed Feb 2, 2015
1 parent 478d539 commit e349e24
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/ViewDataTable/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
namespace Piwik\ViewDataTable;

use Piwik\Cache;
use Piwik\Common;
use Piwik\Option;
use Piwik\Piwik;
Expand Down Expand Up @@ -63,6 +64,14 @@ public static function getIdsWithInheritance($klass)
*/
public static function getAvailableViewDataTables()
{
$cache = Cache::getTransientCache();
$cacheId = 'ViewDataTable.getAvailableViewDataTables';
$dataTables = $cache->fetch($cacheId);

if (!empty($dataTables)) {
return $dataTables;
}

$klassToExtend = '\\Piwik\\Plugin\\ViewDataTable';

/** @var string[] $visualizations */
Expand Down Expand Up @@ -107,6 +116,8 @@ public static function getAvailableViewDataTables()
$result[$vizId] = $viz;
}

$cache->save($cacheId, $result);

return $result;
}

Expand Down

2 comments on commit e349e24

@mattab
Copy link
Member

@mattab mattab commented on e349e24 Feb 9, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As previous comment, here also cache could be invalidated on plugin (de)activate

@tsteur
Copy link
Member Author

@tsteur tsteur commented on e349e24 Feb 9, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't make sense to me. Can you explain? Plugins are loaded in the beginning of the request so should be no problem. Would only make it more complex or not?

Please sign in to comment.