Commit 3e9e4235 authored by Marcelo Rivera's avatar Marcelo Rivera

(feat): implemented new offsets from v2/boost/feeds

1 merge request!235WIP: Boost Campaigns (&24)
Pipeline #71747297 running with stages
......@@ -9,6 +9,7 @@ namespace Minds\Controllers\api\v2\boost\fetch;
use Minds\Api\Exportable;
use Minds\Api\Factory;
use Minds\Common\Urn;
use Minds\Core;
use Minds\Core\Boost;
use Minds\Core\Boost\Campaigns\Campaign;
use Minds\Core\Boost\Network;
......@@ -36,23 +37,31 @@ class campaigns implements Interfaces\Api
// Parse parameters
$type = $pages[0] ?? 'newsfeed';
if (!in_array($type, ['newsfeed', 'content'])) {
return Factory::response([
'status' => 'error',
'message' => 'Unsupported boost type',
]);
}
$limit = abs(intval($_GET['limit'] ?? 2));
$offset = $_GET['offset'] ?? 0;
$rating = intval($_GET['rating'] ?? $currentUser->getBoostRating());
$platform = $_GET['platform'] ?? 'other';
$quality = 0;
$sync = (bool) ($_GET['sync'] ?? true);
if ($limit === 0) {
return Factory::response([
'boosts' => [],
]);
} elseif ($sync && $limit > 500) {
} elseif ($limit > 500) {
$limit = 500;
} elseif (!$sync && $limit > 50) {
$limit = 50;
}
$cacher = Core\Data\cache\factory::build('Redis');
$cacheKey = Core\Session::getLoggedinUser()->guid . ':boost-offset-rotator:' . $type;
$offset = $cacher->get($cacheKey);
// Options specific to newly created users (<=1 hour) and iOS users
if ($platform === 'ios') {
......@@ -95,6 +104,17 @@ class campaigns implements Interfaces\Api
$data[] = $feedSyncEntity;
}
if (isset($data[2])) { // Always offset to 3rd in list
$offset += 2;
}
$ttl = 1800; // 30 minutes
if (($data / 1000) < strtotime('48 hours ago')) {
$ttl = 300; // 5 minutes;
}
$cacher->set($cacheKey, $offset, $ttl);
} catch (\Exception $e) {
error_log($e);
}
......
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