Remove json 'cache' files from anime model

This commit is contained in:
Timothy Warren 2016-04-07 12:32:32 -04:00
parent 181af86899
commit 5db1d8b494
2 changed files with 6 additions and 24 deletions

View File

@ -57,7 +57,6 @@ class Model {
*/ */
public function get_cached_image($api_path, $series_slug, $type = "anime") public function get_cached_image($api_path, $series_slug, $type = "anime")
{ {
$api_path = str_replace("jjpg", "jpg", $api_path);
$path_parts = explode('?', basename($api_path)); $path_parts = explode('?', basename($api_path));
$path = current($path_parts); $path = current($path_parts);
$ext_parts = explode('.', $path); $ext_parts = explode('.', $path);

View File

@ -223,7 +223,7 @@ class Anime extends API {
} }
$response = $this->get("users/{$username}/library", $config); $response = $this->get("users/{$username}/library", $config);
$output = $this->_check_cache($status, $response); $output = $this->transform($status, $response);
foreach ($output as &$row) foreach ($output as &$row)
{ {
@ -234,35 +234,18 @@ class Anime extends API {
} }
/** /**
* Handle caching of transformed api data * Handle transforming of api data
* *
* @codeCoverageIgnore
* @param string $status * @param string $status
* @param \GuzzleHttp\Message\Response * @param \GuzzleHttp\Message\Response
* @return array * @return array
*/ */
protected function _check_cache($status, $response) protected function transform($status, $response)
{ {
$cache_file = _dir($this->config->get('data_cache_path'), "anime-{$status}.json");
$transformed_cache_file = _dir($this->config->get('data_cache_path'), "anime-{$status}-transformed.json");
$cached = (file_exists($cache_file))
? Json::decodeFile($cache_file)
: [];
$api_data = Json::decode($response->getBody(), TRUE); $api_data = Json::decode($response->getBody(), TRUE);
if ($api_data === $cached && file_exists($transformed_cache_file))
{
return Json::decodeFile($transformed_cache_file);
}
else
{
Json::encodeFile($cache_file, $api_data);
$transformer = new AnimeListTransformer(); $transformer = new AnimeListTransformer();
$transformed = $transformer->transform_collection($api_data); $transformed = $transformer->transform_collection($api_data);
Json::encodeFile($transformed_cache_file, $transformed);
return $transformed; return $transformed;
} }
} }
}
// End of AnimeModel.php // End of AnimeModel.php