mirror of
https://github.com/AzuraCast/AzuraCast.git
synced 2024-06-14 13:16:37 +00:00
Smarter caching for conventions that automatically clears with changes.
This commit is contained in:
parent
9d617e1b54
commit
fcc30880f0
|
@ -115,6 +115,23 @@ class Convention extends \DF\Doctrine\Entity
|
|||
* Static Functions
|
||||
*/
|
||||
|
||||
public static function getAllConventions()
|
||||
{
|
||||
$all_cons = \DF\Cache::get('homepage_conventions');
|
||||
|
||||
if (!$all_cons)
|
||||
{
|
||||
$all_cons = array(
|
||||
'upcoming' => self::getUpcomingConventions(),
|
||||
'archived' => self::getConventionsWithArchives(),
|
||||
);
|
||||
|
||||
\DF\Cache::save($all_cons, 'homepage_conventions', array(), 1800);
|
||||
}
|
||||
|
||||
return $all_cons;
|
||||
}
|
||||
|
||||
public static function getUpcomingConventions()
|
||||
{
|
||||
$em = self::getEntityManager();
|
||||
|
@ -125,7 +142,6 @@ class Convention extends \DF\Doctrine\Entity
|
|||
$conventions = $em->createQuery('SELECT c FROM '.__CLASS__.' c WHERE (c.start_date <= :end AND c.end_date >= :start) ORDER BY c.start_date ASC')
|
||||
->setParameter('start', gmdate('Y-m-d', $start_timestamp))
|
||||
->setParameter('end', gmdate('Y-m-d', $end_timestamp))
|
||||
->useResultCache(true, 1800, 'pvl_upcoming_conventions')
|
||||
->getArrayResult();
|
||||
|
||||
$coverage = self::getCoverageLevels();
|
||||
|
@ -144,7 +160,6 @@ class Convention extends \DF\Doctrine\Entity
|
|||
|
||||
$conventions = $em->createQuery('SELECT c FROM '.__CLASS__.' c LEFT JOIN c.archives ca WHERE ca.id IS NOT NULL AND (c.start_date <= :now) GROUP BY c.id ORDER BY c.start_date DESC')
|
||||
->setParameter('now', gmdate('Y-m-d', time()))
|
||||
->useResultCache(true, 1800, 'pvl_archived_conventions')
|
||||
->getArrayResult();
|
||||
|
||||
$coverage = self::getCoverageLevels();
|
||||
|
|
|
@ -29,6 +29,10 @@ class Admin_ConventionsController extends \DF\Controller\Action
|
|||
throw new \DF\Exception\DisplayOnly('Convention ID not found!');
|
||||
}
|
||||
}
|
||||
protected function _flushConventionCache()
|
||||
{
|
||||
\DF\Cache::remove('homepage_conventions');
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
|
@ -58,14 +62,14 @@ class Admin_ConventionsController extends \DF\Controller\Action
|
|||
|
||||
$files = $form->processFiles('conventions');
|
||||
|
||||
\DF\Utilities::print_r($files);
|
||||
|
||||
foreach($files as $file_field => $file_paths)
|
||||
$data[$file_field] = $file_paths[1];
|
||||
|
||||
$record->fromArray($data);
|
||||
$record->save();
|
||||
|
||||
$this->_flushConventionCache();
|
||||
|
||||
$this->alert('Changes saved.', 'green');
|
||||
$this->redirectFromHere(array('action' => 'index', 'id' => NULL));
|
||||
return;
|
||||
|
@ -81,6 +85,8 @@ class Admin_ConventionsController extends \DF\Controller\Action
|
|||
if ($record)
|
||||
$record->delete();
|
||||
|
||||
$this->_flushConventionCache();
|
||||
|
||||
$this->alert('Record deleted.', 'green');
|
||||
$this->redirectFromHere(array('action' => 'index', 'id' => NULL, 'csrf' => NULL));
|
||||
}
|
||||
|
|
|
@ -25,8 +25,9 @@ class IndexController extends \DF\Controller\Action
|
|||
$this->_initStations();
|
||||
|
||||
// Pull conventions.
|
||||
$this->view->conventions_upcoming = Convention::getUpcomingConventions();
|
||||
$this->view->conventions_archived = Convention::getConventionsWithArchives();
|
||||
$conventions = Convention::getAllConventions();
|
||||
$this->view->conventions_upcoming = $conventions['upcoming'];
|
||||
$this->view->conventions_archived = $conventions['archived'];
|
||||
|
||||
// Pull rotators.
|
||||
$rotators = Rotator::fetch();
|
||||
|
|
Loading…
Reference in New Issue
Block a user