Make Things Faster!

- Implement caching on footer Affiliate section
 - Restyle footer affiliate section to dynamically form columns
 - Integrate sub-templates into main template to reduce load calls
 - Cache schedule lookups (for much faster homepage loading)
This commit is contained in:
Buster Silver 2015-05-18 00:42:02 -05:00
parent cf03ca9cf7
commit d8b739c443
9 changed files with 217 additions and 199 deletions

View File

@ -62,13 +62,19 @@ class Affiliate extends \DF\Doctrine\Entity
public static function fetch($only_approved = true)
{
$records = self::fetchArray();
$cache_name = 'pvlive_affiliates_'.(($only_approved) ? 'approved' : 'all');
$records = \DF\Cache::get($cache_name);
if ($only_approved)
$records = array_filter($records, function($record) { return $record['is_approved']; });
if (!$records)
{
$records = self::fetchArray();
if ($only_approved)
$records = array_filter($records, function ($record) { return $record['is_approved']; });
\DF\Cache::set($records, $cache_name, array(), 60);
}
shuffle($records);
return $records;
}
}

View File

@ -1,6 +1,8 @@
<?php
namespace Modules\Frontend\Controllers;
use DF\Cache;
use Entity\Station;
use Entity\Podcast;
use Entity\NetworkNews;
@ -24,17 +26,20 @@ class IndexController extends BaseController
$network_news = NetworkNews::fetchFeatured();
$this->view->network_news = $network_news;
// Pull stations.
// Pull stations and calendar events.
$this->_initStations();
$this->_initEvents();
// Pull conventions.
$conventions = Convention::getAllConventions();
$this->view->conventions_upcoming = $conventions['upcoming'];
$this->view->conventions_archived = $conventions['archived'];
/*
// Pull rotators.
$rotators = Rotator::fetch();
$this->view->rotators = $rotators;
*/
// Special event flagging and special formatting.
$special_event = \PVL\Utilities::showSpecialEventsMode();
@ -55,8 +60,6 @@ class IndexController extends BaseController
}
$this->view->autoplay = (bool)$this->getParam('autoplay', true);
$this->view->pick('index/index');
}
public function tuneinAction()
@ -141,12 +144,13 @@ class IndexController extends BaseController
public function scheduleAction()
{
// Pull stations.
$this->_initStations();
$this->_initEvents();
}
public function upcomingAction()
{
$this->_initStations();
$this->_initEvents();
$id = $this->view->station_id;
@ -190,14 +194,14 @@ class IndexController extends BaseController
$this->view->station_id = $station_id = $this->getParam('id', NULL);
$this->view->volume = ($this->hasParam('volume')) ? (int)$this->getParam('volume') : 30;
$this->categories = \Entity\Station::getCategories();
$this->categories = Station::getCategories();
$stations_raw = Station::fetchArray();
// Limit to a single station if requested.
if ($station_id && $this->getParam('showonlystation', false) == 'true')
{
foreach($stations_raw as $station)
foreach ($stations_raw as $station)
{
if ($station['id'] == $station_id)
{
@ -208,13 +212,13 @@ class IndexController extends BaseController
}
$this->stations = array();
foreach($stations_raw as $station)
foreach ($stations_raw as $station)
{
// Build multi-stream directory.
$streams = array();
$current_stream_id = NULL;
foreach((array)$station['streams'] as $stream)
foreach ((array)$station['streams'] as $stream)
{
if (!$stream['hidden_from_player'] && $stream['is_active'])
{
@ -246,7 +250,7 @@ class IndexController extends BaseController
$this->stations[$station['id']] = $station;
}
foreach($this->stations as $station)
foreach ($this->stations as $station)
{
if (isset($this->categories[$station['category']]))
$this->categories[$station['category']]['stations'][] = $station;
@ -254,63 +258,73 @@ class IndexController extends BaseController
$this->view->stations = $this->stations;
$this->view->categories = $this->categories;
}
/**
* Compose events
*/
protected function _initEvents()
{
$event_info = Cache::get('pvlive_events');
$events_raw = $this->em->createQuery('SELECT s, st FROM Entity\Schedule s JOIN s.station st WHERE (s.end_time >= :current AND s.start_time <= :future) ORDER BY s.start_time ASC')
->setParameter('current', time())
->setParameter('future', strtotime('+1 week'))
->getArrayResult();
$all_events = array();
$events_by_day = array();
for($i = 0; $i < 6; $i++)
if (!$event_info)
{
$day_timestamp = mktime(0, 0, 1, date('n'), (int)date('j') + $i);
$day_date = date('Y-m-d', $day_timestamp);
$events_raw = $this->em->createQuery('SELECT s, st FROM Entity\Schedule s JOIN s.station st WHERE (s.end_time >= :current AND s.start_time <= :future) ORDER BY s.start_time ASC')
->setParameter('current', time())
->setParameter('future', strtotime('+4 days'))
->getArrayResult();
$is_today = ($day_date == date('Y-m-d'));
$all_events = array();
$events_by_day = array();
$events_by_day[$day_date] = array(
'day_name' => ($is_today) ? 'Today' : date('l', $day_timestamp),
'timestamp' => $day_timestamp,
'is_today' => $is_today,
'events' => array(),
);
}
foreach($events_raw as $event)
{
$event['image_url'] = \DF\Url::content(Schedule::getRowImageUrl($event));
$event['status'] = ($event['start_time'] <= time()) ? 'now' : 'upcoming';
$event['range'] = Schedule::getRangeText($event['start_time'], $event['end_time'], $event['is_all_day']);
if ($event['station_id'])
for ($i = 0; $i < 6; $i++)
{
$sid = $event['station_id'];
$day_timestamp = mktime(0, 0, 1, date('n'), (int)date('j') + $i);
$day_date = date('Y-m-d', $day_timestamp);
if (isset($this->stations[$sid]))
{
$event['station'] = $this->stations[$sid];
$this->stations[$sid]['events'][] = $event;
$is_today = ($day_date == date('Y-m-d'));
if ($event['status'] == "now")
$this->stations[$sid]['now'] = $event;
}
$events_by_day[$day_date] = array(
'day_name' => ($is_today) ? 'Today' : date('l', $day_timestamp),
'timestamp' => $day_timestamp,
'is_today' => $is_today,
'events' => array(),
);
}
$all_events[] = $event;
foreach ($events_raw as $event)
{
$event['image_url'] = \DF\Url::content(Schedule::getRowImageUrl($event));
$event['status'] = ($event['start_time'] <= time()) ? 'now' : 'upcoming';
$event['range'] = Schedule::getRangeText($event['start_time'], $event['end_time'], $event['is_all_day']);
$event_date = date('Y-m-d', $event['start_time']);
if (isset($events_by_day[$event_date]))
$events_by_day[$event_date]['events'][] = $event;
if ($event['station_id'])
{
$sid = $event['station_id'];
if (isset($this->stations[$sid]))
{
$station = $this->stations[$sid];
unset($station['nowplaying_data'], $station['streams'], $station['intake_votes']);
$event['station'] = $station;
}
}
$all_events[] = $event;
$event_date = date('Y-m-d', $event['start_time']);
if (isset($events_by_day[$event_date]))
$events_by_day[$event_date]['events'][] = $event;
}
$event_info = array(
'all' => $all_events,
'by_day' => $events_by_day,
);
Cache::save($event_info, 'pvlive_events', array(), 60);
}
$this->view->events_by_day = $events_by_day;
$this->view->all_events = $all_events;
$this->view->all_events = $event_info['all'];
$this->view->events_by_day = $event_info['by_day'];
}
public function nowplayingAction()

View File

@ -86,7 +86,37 @@ $tz_info = \PVL\Timezone::getInfo();
<div class="top">
<div class="container">
<?php $this->viewHelper->renderCommon("usernav") ?>
<?
$skin = \PVL\Customization::get('theme');
$tz_info = \PVL\Timezone::getInfo();
$tz_text = $tz_info['now']->format('g:ia');
?>
<ul class="loginbar pull-right">
<li><a href="<?=$this->url->get('profile/timezone') ?>" class="fancybox fancybox.ajax"><i class="icon-time"></i> <span class="current_time"><?=$tz_text ?></span> <?=$tz_info['abbr'] ?></a></li>
<li class="divider">&nbsp;</li>
<li><a href="<?=$this->url->get('profile/theme/skin/toggle') ?>"><i class="icon-adjust"></i> <? if ($skin == 'light'): ?>Dark Theme<? else: ?>Light Theme<? endif; ?></a></li>
<li class="divider">&nbsp;</li>
<? if ($this->auth->isLoggedIn()): ?>
<?
$user = $this->auth->getLoggedInUser();
?>
<? if ($this->acl->isAllowed('view administration')): ?>
<li><a href="<?=$this->url->get('admin') ?>"><i class="icon-cog"></i> Admin</a></li>
<li class="divider">&nbsp;</li>
<? elseif (\Entity\Station::canSeeStationCenter($user)): ?>
<li><a href="<?=$this->url->get('stations') ?>"><i class="icon-group"></i> Station Center</a></li>
<li class="divider">&nbsp;</li>
<? endif; ?>
<li><a href="<?=$this->url->get('profile') ?>"><i class="icon-user"></i> Profile</a></li>
<li class="divider">&nbsp;</li>
<li><b><?=$user->name ?></b></li>
<li><a href="<?=$this->url->get('account/logout') ?>"><i class="icon-signout"></i> Sign Out</a></li>
<? else: ?>
<li><a href="<?=$this->url->get('account/login') ?>"><i class="icon-signin"></i> Sign In</a></li>
<? endif; ?>
</ul>
</div>
</div>
@ -104,7 +134,74 @@ $tz_info = \PVL\Timezone::getInfo();
<span class="icon-bar"></span>
</a>
<div class="nav-collapse collapse" role="navigation">
<?php $this->viewHelper->renderCommon("nav") ?>
<?
$categories = \Entity\Station::getStationsInCategories();
$podcasts = \Entity\Podcast::fetchArray();
?>
<ul class="nav primary_menu">
<!-- About PVL -->
<li class="dropdown">
<a href="<?=$this->url->get('about') ?>"><i class="icon-info-sign"></i> About</a>
<ul class="dropdown-menu">
<li><a href="<?=$this->url->get('about') ?>"><i class="icon-info-sign"></i> About Us</a></li>
<li><a href="<?=$this->url->get('contact') ?>"><i class="icon-envelope"></i> Contact Us</a></li>
<li><a href="<?=$this->url->get('donate') ?>"><i class="icon-money"></i> Support Us</a></li>
<li class="divider"></li>
<li><a href="http://m.pvlive.me/"><i class="icon-mobile-phone"></i> PVL! Mobile</a></li>
<li><a href="<?=$this->url->get('apps') ?>"><i class="icon-cloud-download"></i> Apps &amp; Players</a></li>
<li><a href="http://docs.ponyvillelive.apiary.io/" target="_blank"><i class="icon-cog"></i> PVL! Data API</a></li>
</ul>
</li>
<!-- Stations -->
<li class="dropdown">
<a href="#" data-toggle="dropdown"><i class="icon-music"></i> Radio</a>
<ul class="dropdown-menu">
<li><a href="<?=$this->url->get('schedule') ?>"><i class="icon-calendar"></i> Station Schedules</a></li>
<li><a href="<?=$this->url->get('submit/station') ?>"><i class="icon-cloud-upload"></i> Submit a Station</a></li>
<li class="divider"></li>
<? foreach($categories['audio']['stations'] as $station): ?>
<li><a href="<?=$station['web_url'] ?>" title="<?=$station['genre'] ?>" target="_blank"><?=$station['name'] ?></a></li>
<? endforeach; ?>
</ul>
</li>
<li class="dropdown">
<a href="#" data-toggle="dropdown"><i class="icon-facetime-video"></i> Video</a>
<ul class="dropdown-menu">
<li><a href="<?=$this->url->get('schedule') ?>"><i class="icon-calendar"></i> Station Schedules</a></li>
<li><a href="<?=$this->url->get('submit/station') ?>"><i class="icon-cloud-upload"></i> Submit a Station</a></li>
<li class="divider"></li>
<? foreach($categories['video']['stations'] as $station): ?>
<li><a href="<?=$station['web_url'] ?>" title="<?=$station['genre'] ?>" target="_blank"><?=$station['name'] ?></a></li>
<? endforeach; ?>
</ul>
</li>
<li class="dropdown">
<a href="#" data-toggle="dropdown"><i class="icon-rss"></i> Shows</a>
<ul class="dropdown-menu">
<li><a href="<?=$this->url->get('shows') ?>"><i class="icon-list"></i> Show Directory</a></li>
<li><a href="<?=$this->url->get('submit/show') ?>"><i class="icon-cloud-upload"></i> Submit a Show</a></li>
<li class="divider"></li>
<? foreach($podcasts as $podcast): ?>
<li><a href="<?=$this->url->get('show/view/id/'.$podcast['id']) ?>" title="<?=$podcast['description'] ?>" target="_blank"><?=$podcast['name'] ?></a></li>
<? endforeach; ?>
</ul>
</li>
<li class="dropdown">
<a href="#" data-toggle="dropdown"><i class="icon-user"></i> Community</a>
<ul class="dropdown-menu">
<li><a href="<?=$this->url->get('conventions') ?>"><i class="icon-building"></i> Pony Conventions</a></li>
<li><a href="<?=$this->url->get('artists') ?>"><i class="icon-group"></i> Artists Directory</a></li>
<li class="divider"></li>
<li><a href="http://pvlive.me/forums" target="_blank">PVL Forums</a></li>
<li><a href="<?=$this->url->get('index/chat') ?>">Chat + Player</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
@ -172,7 +269,34 @@ $tz_info = \PVL\Timezone::getInfo();
<div class="footer" role="contentinfo">
<div class="container">
<?=$this->viewHelper->renderCommon('footer') ?>
<?
$affiliates = \Entity\Affiliate::fetch(true);
?>
<div class="footer-inner">
<div class="row-fluid row-multiple clearfix">
<div class="media-list">
<? foreach($affiliates as $affiliate): ?>
<div class="media span4">
<div class="media-object pull-left">
<a href="<?=$affiliate['web_url'] ?>" target="_blank">
<img src="<?=\DF\Url::content($affiliate['image_url']) ?>" alt="<?=$affiliate['name'] ?> Logo" style="width: 40px;">
</a>
</div>
<div class="media-body">
<h4>
<? if (isset($affiliate['custom'])): ?>
<?=$affiliate['custom'] ?><br>
<? else: ?>
<a href="<?=$affiliate['web_url'] ?>" target="_blank"><?=$affiliate['name'] ?></a><br>
<? endif; ?>
<small><?=$affiliate['description'] ?></small>
</h4>
</div>
</div>
<? endforeach; ?>
</div>
</div>
</div>
</div>
</div>

View File

@ -1,33 +0,0 @@
<?
$affiliates = \Entity\Affiliate::fetch(true);
$columns = \DF\Utilities::columns($affiliates, 3);
?>
<div class="footer-inner">
<div class="row-fluid">
<? foreach($columns as $column): ?>
<div class="span4">
<ul class="media-list">
<? foreach($column as $affiliate): ?>
<li class="media">
<div class="media-object pull-left">
<a href="<?=$affiliate['web_url'] ?>" target="_blank">
<img src="<?=\DF\Url::content($affiliate['image_url']) ?>" alt="<?=$affiliate['name'] ?> Logo" style="width: 40px;">
</a>
</div>
<div class="media-body">
<h4>
<? if (isset($affiliate['custom'])): ?>
<?=$affiliate['custom'] ?><br>
<? else: ?>
<a href="<?=$affiliate['web_url'] ?>" target="_blank"><?=$affiliate['name'] ?></a><br>
<? endif; ?>
<small><?=$affiliate['description'] ?></small>
</h4>
</div>
</li>
<? endforeach; ?>
</ul>
</div>
<? endforeach; ?>
</div>
</div>

View File

@ -1,70 +0,0 @@
<?
$categories = \Entity\Station::getStationsInCategories();
$podcasts = \Entity\Podcast::fetchArray();
?>
<ul class="nav primary_menu">
<!-- About PVL -->
<li class="dropdown">
<a href="<?=$this->url->get('about') ?>"><i class="icon-info-sign"></i> About</a>
<ul class="dropdown-menu">
<li><a href="<?=$this->url->get('about') ?>"><i class="icon-info-sign"></i> About Us</a></li>
<li><a href="<?=$this->url->get('contact') ?>"><i class="icon-envelope"></i> Contact Us</a></li>
<li><a href="<?=$this->url->get('donate') ?>"><i class="icon-money"></i> Support Us</a></li>
<li class="divider"></li>
<li><a href="http://m.pvlive.me/"><i class="icon-mobile-phone"></i> PVL! Mobile</a></li>
<li><a href="<?=$this->url->get('apps') ?>"><i class="icon-cloud-download"></i> Apps &amp; Players</a></li>
<li><a href="http://docs.ponyvillelive.apiary.io/" target="_blank"><i class="icon-cog"></i> PVL! Data API</a></li>
</ul>
</li>
<!-- Stations -->
<li class="dropdown">
<a href="#" data-toggle="dropdown"><i class="icon-music"></i> Radio</a>
<ul class="dropdown-menu">
<li><a href="<?=$this->url->get('schedule') ?>"><i class="icon-calendar"></i> Station Schedules</a></li>
<li><a href="<?=$this->url->get('submit/station') ?>"><i class="icon-cloud-upload"></i> Submit a Station</a></li>
<li class="divider"></li>
<? foreach($categories['audio']['stations'] as $station): ?>
<li><a href="<?=$station['web_url'] ?>" title="<?=$station['genre'] ?>" target="_blank"><?=$station['name'] ?></a></li>
<? endforeach; ?>
</ul>
</li>
<li class="dropdown">
<a href="#" data-toggle="dropdown"><i class="icon-facetime-video"></i> Video</a>
<ul class="dropdown-menu">
<li><a href="<?=$this->url->get('schedule') ?>"><i class="icon-calendar"></i> Station Schedules</a></li>
<li><a href="<?=$this->url->get('submit/station') ?>"><i class="icon-cloud-upload"></i> Submit a Station</a></li>
<li class="divider"></li>
<? foreach($categories['video']['stations'] as $station): ?>
<li><a href="<?=$station['web_url'] ?>" title="<?=$station['genre'] ?>" target="_blank"><?=$station['name'] ?></a></li>
<? endforeach; ?>
</ul>
</li>
<li class="dropdown">
<a href="#" data-toggle="dropdown"><i class="icon-rss"></i> Shows</a>
<ul class="dropdown-menu">
<li><a href="<?=$this->url->get('shows') ?>"><i class="icon-list"></i> Show Directory</a></li>
<li><a href="<?=$this->url->get('submit/show') ?>"><i class="icon-cloud-upload"></i> Submit a Show</a></li>
<li class="divider"></li>
<? foreach($podcasts as $podcast): ?>
<li><a href="<?=$this->url->get('show/view/id/'.$podcast['id']) ?>" title="<?=$podcast['description'] ?>" target="_blank"><?=$podcast['name'] ?></a></li>
<? endforeach; ?>
</ul>
</li>
<li class="dropdown">
<a href="#" data-toggle="dropdown"><i class="icon-user"></i> Community</a>
<ul class="dropdown-menu">
<li><a href="<?=$this->url->get('conventions') ?>"><i class="icon-building"></i> Pony Conventions</a></li>
<li><a href="<?=$this->url->get('artists') ?>"><i class="icon-group"></i> Artists Directory</a></li>
<li class="divider"></li>
<li><a href="http://pvlive.me/forums" target="_blank">PVL Forums</a></li>
<li><a href="<?=$this->url->get('index/chat') ?>">Chat + Player</a></li>
</ul>
</li>
<li></li>
</ul>

View File

@ -1,31 +0,0 @@
<?
$skin = \PVL\Customization::get('theme');
$tz_info = \PVL\Timezone::getInfo();
$tz_text = $tz_info['now']->format('g:ia');
?>
<ul class="loginbar pull-right">
<li><a href="<?=$this->url->get('profile/timezone') ?>" class="fancybox fancybox.ajax"><i class="icon-time"></i> <span class="current_time"><?=$tz_text ?></span> <?=$tz_info['abbr'] ?></a></li>
<li class="divider">&nbsp;</li>
<li><a href="<?=$this->url->get('profile/theme/skin/toggle') ?>"><i class="icon-adjust"></i> <? if ($skin == 'light'): ?>Dark Theme<? else: ?>Light Theme<? endif; ?></a></li>
<li class="divider">&nbsp;</li>
<? if ($this->auth->isLoggedIn()): ?>
<?
$user = $this->auth->getLoggedInUser();
?>
<? if ($this->acl->isAllowed('view administration')): ?>
<li><a href="<?=$this->url->get('admin') ?>"><i class="icon-cog"></i> Admin</a></li>
<li class="divider">&nbsp;</li>
<? elseif (\Entity\Station::canSeeStationCenter($user)): ?>
<li><a href="<?=$this->url->get('stations') ?>"><i class="icon-group"></i> Station Center</a></li>
<li class="divider">&nbsp;</li>
<? endif; ?>
<li><a href="<?=$this->url->get('profile') ?>"><i class="icon-user"></i> Profile</a></li>
<li class="divider">&nbsp;</li>
<li><b><?=$user->name ?></b></li>
<li><a href="<?=$this->url->get('account/logout') ?>"><i class="icon-signout"></i> Sign Out</a></li>
<? else: ?>
<li><a href="<?=$this->url->get('account/login') ?>"><i class="icon-signin"></i> Sign In</a></li>
<? endif; ?>
</ul>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -7,7 +7,7 @@
border-top: 2px solid #4878B3;
.container .footer-inner {
padding: 0 15px;
padding: 0 10px;
}
h1, h2, h3, h4, h5 {
@ -37,6 +37,7 @@
color:#e4e4e4;
background:none;
text-shadow:none;
line-height: 20px;
}
.media-object {
@ -51,6 +52,13 @@
border: 0;
}
.media-list {
margin-top: -10px;
}
.media {
margin-top: 10px;
}
.dl-horizontal a:hover {
color: #3498db !important;
}