Skip to content

Commit a2e259c

Browse files
authored
Merge pull request #732 from joomlatools/feature/731-containers-cache
Cache fetched containers
2 parents df868b7 + a0002b3 commit a2e259c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

code/libraries/joomlatools-components/files/model/containers.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
class ComFilesModelContainers extends KModelDatabase
1717
{
18+
public static $containers = array();
19+
1820
protected function _buildQueryWhere(KDatabaseQueryInterface $query)
1921
{
2022
parent::_buildQueryWhere($query);
@@ -25,4 +27,33 @@ protected function _buildQueryWhere(KDatabaseQueryInterface $query)
2527
$query->where('tbl.title LIKE :search')->bind(array('search' => '%'.$state->search.'%'));
2628
}
2729
}
30+
31+
/**
32+
* Override fetch method to handle caching of unique result
33+
*
34+
* @param KModelContext $context
35+
* @return KModelEntityInterface
36+
*/
37+
protected function _actionFetch(KModelContext $context)
38+
{
39+
$state = $this->getState();
40+
41+
if ($state->isUnique() && $state->has('slug'))
42+
{
43+
$slug = $state->slug;
44+
45+
if (!isset(self::$containers[$slug]))
46+
{
47+
$container = parent::_actionFetch($context);
48+
49+
if (!$container->isNew()) {
50+
self::$containers[$slug] = $container;
51+
}
52+
}
53+
else $container = self::$containers[$slug];
54+
}
55+
else $container = parent::_actionFetch($context);
56+
57+
return $container;
58+
}
2859
}

0 commit comments

Comments
 (0)