Update manga model to cache the one api response.

This commit is contained in:
Timothy Warren 2016-04-12 13:41:03 -04:00
parent 7d6c6fe2a0
commit e26e9f10b6
5 changed files with 16 additions and 1021 deletions

View File

@ -40,6 +40,9 @@ return function(array $config_array = []) {
$config = new Config($config_array);
$container->set('config', $config);
// Create Cache Object
$container->set('cache', new CacheManager($container));
// Create Aura Router Object
$container->set('aura-router', new RouterContainer);
@ -80,7 +83,6 @@ return function(array $config_array = []) {
// Miscellaneous Classes
$container->set('auth', new HummingbirdAuth($container));
$container->set('cache', new CacheManager($container));
$container->set('url-generator', new UrlGenerator($container));
// -------------------------------------------------------------------------

View File

@ -26,12 +26,6 @@ class Manga extends Controller {
use \Aviat\Ion\StringWrapper;
/**
* The cache manager
* @var \Aviat\Ion\Cache\CacheInterface
*/
protected $cache;
/**
* The manga model
* @var object $model
@ -53,7 +47,6 @@ class Manga extends Controller {
{
parent::__construct($container);
$this->cache = $container->get('cache');
$this->model = $container->get('manga-model');
$this->base_data = array_merge($this->base_data, [
'menu_name' => 'manga_list',
@ -89,8 +82,8 @@ class Manga extends Controller {
];
$data = ($status !== 'all')
? [$map[$status] => $this->cache->get($this->model, 'get_list', ['status' => $map[$status]]) ]
: $this->cache->get($this->model, 'get_all_lists');
? [$map[$status] => $this->model->get_list($map[$status]) ]
: $this->model->get_list('All');
$this->outputHTML('manga/' . $view_map[$view], [
'title' => $title,

View File

@ -168,23 +168,6 @@ class Manga extends API {
return Json::decode($response->getBody(), TRUE);
}
/**
* Get the full set of anime lists
*
* @return array
*/
public function get_all_lists()
{
$data = $this->_get_list_from_api();
foreach ($data as &$val)
{
$this->sort_by_name($val, 'manga');
}
return $data;
}
/**
* Get a category out of the full list
*
@ -193,10 +176,8 @@ class Manga extends API {
*/
public function get_list($status)
{
$data = $this->_get_list_from_api($status);
$this->sort_by_name($data, 'manga');
return $data;
$data = $this->cache->get($this, '_get_list_from_api');
return ($status !== 'All') ? $data[$status] : $data;
}
/**
@ -205,7 +186,7 @@ class Manga extends API {
* @param string $status
* @return array
*/
protected function _get_list_from_api($status = "All")
public function _get_list_from_api($status = "All")
{
$config = [
'query' => [
@ -216,11 +197,7 @@ class Manga extends API {
$response = $this->get('manga_library_entries', $config);
$data = $this->transform($response);
$output = $this->map_by_status($data);
return (array_key_exists($status, $output))
? $output[$status]
: $output;
return $this->map_by_status($data);
}
/**
@ -242,6 +219,7 @@ class Manga extends API {
$zippered_data = $this->zipper_lists($api_data);
$transformer = new Transformer\MangaListTransformer();
$transformed_data = $transformer->transform_collection($zippered_data);
return $transformed_data;
}
@ -272,6 +250,11 @@ class Manga extends API {
$output[$key][] = $entry;
}
foreach($output as &$val)
{
$this->sort_by_name($val, 'manga');
}
return $output;
}

View File

@ -71,21 +71,4 @@ class MangaModelTest extends AnimeClient_TestCase {
$expected = Json::decodeFile($this->mockDir . '/get-all-lists.json');
$this->assertEquals($expected['Reading'], $this->model->get_list('Reading'));
}
public function testGetAllLists()
{
if (($var = getenv('CI')))
{
$this->markTestSkipped();
}
$data = file_get_contents($this->mockDir . '/manga.json');
$client = $this->getMockClient(200, [
'Content-type' => 'application/json'
], $data);
$this->model->__set('client', $client);
$expected = Json::decodeFile($this->mockDir . '/get-all-lists.json');
$this->assertEquals($expected, $this->model->get_all_lists());
}
}

File diff suppressed because one or more lines are too long