Commit bf5c71db authored by Emiliano Balbuena's avatar Emiliano Balbuena

(refactor): Cache tag breakdown content instead of top Pro feed

1 merge request!308WIP: (feat): Minds Pro
Pipeline #82518841 failed with stages
in 10 minutes and 21 seconds
......@@ -116,11 +116,6 @@ class channel implements Interfaces\Api
$custom_type = isset($_GET['custom_type']) && $_GET['custom_type'] ? [$_GET['custom_type']] : null;
$cache = (bool) $_GET['cache'] ?? true;
/** @var Core\Data\cache\abstractCacher $cacher */
$cacher = Di::_()->get('Cache');
/** @var Core\Feeds\Top\Entities $entities */
$entities = new Core\Feeds\Top\Entities();
$entities->setActor($currentUser);
......@@ -169,15 +164,6 @@ class channel implements Interfaces\Api
$opts['filter_hashtags'] = true;
}
$cacheKey = $this->getCacheKey($opts);
if ($cache) {
$cached = $cacher->get($cacheKey);
if ($cached && count($cached) > 0) {
return Factory::response($cached);
}
}
try {
$result = $this->getData($entities, $opts, $asActivities, $sync);
......@@ -192,10 +178,6 @@ class channel implements Interfaces\Api
'load-next' => $result->getPagingToken(),
];
if ($cache) {
$cacher->set($cacheKey, $response, 300); // cache for 5 mins
}
return Factory::response($response);
} catch (\Exception $e) {
error_log($e);
......@@ -203,11 +185,6 @@ class channel implements Interfaces\Api
}
}
private function getCacheKey(array $opts): string
{
return "feeds-channel:" . implode(':', $opts);
}
/**
* @param Core\Feeds\Top\Entities $entities
* @param array $opts
......
......@@ -7,6 +7,8 @@
namespace Minds\Core\Pro\Channel;
use Exception;
use Minds\Core\Data\cache\abstractCacher;
use Minds\Core\Di\Di;
use Minds\Core\Feeds\Top\Manager as TopManager;
use Minds\Core\Pro\Repository;
use Minds\Core\Pro\Settings;
......@@ -14,12 +16,17 @@ use Minds\Entities\User;
class Manager
{
const CACHE_TTL = 300; // Cache homepage content for 5 minutes
/** @var Repository */
protected $repository;
/** @var TopManager */
protected $top;
/** @var abstractCacher */
protected $cache;
/** @var User */
protected $user;
......@@ -27,13 +34,16 @@ class Manager
* Manager constructor.
* @param Repository $repository
* @param TopManager $top
* @param abstractCacher $cache
*/
public function __construct(
$repository = null,
$top = null
$top = null,
$cache = null
) {
$this->repository = $repository ?: new Repository();
$this->top = $top ?: new TopManager();
$this->cache = $cache ?: Di::_()->get('Cache');
}
/**
......@@ -65,6 +75,14 @@ class Manager
throw new Exception('Invalid Pro user');
}
$cacheKey = sprintf("pro::v1::getAllCategoriesContent::%s", $this->user->guid);
$cachedContent = $this->cache->get($cacheKey);
if ($cachedContent) {
return $cachedContent;
}
$tags = $settings->getTagList() ?: [];
$output = [];
......@@ -98,6 +116,8 @@ class Manager
];
}
$this->cache->set($cacheKey, $output, static::CACHE_TTL);
return $output;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment