Remove json 'cache' files from anime model
This commit is contained in:
parent
7711765563
commit
440a999c2e
@ -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);
|
||||||
|
@ -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);
|
||||||
|
$transformer = new AnimeListTransformer();
|
||||||
if ($api_data === $cached && file_exists($transformed_cache_file))
|
$transformed = $transformer->transform_collection($api_data);
|
||||||
{
|
return $transformed;
|
||||||
return Json::decodeFile($transformed_cache_file);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Json::encodeFile($cache_file, $api_data);
|
|
||||||
$transformer = new AnimeListTransformer();
|
|
||||||
$transformed = $transformer->transform_collection($api_data);
|
|
||||||
Json::encodeFile($transformed_cache_file, $transformed);
|
|
||||||
return $transformed;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// End of AnimeModel.php
|
// End of AnimeModel.php
|
Loading…
Reference in New Issue
Block a user