Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paging for Episodes and Performance Optimizations #560

Merged
merged 13 commits into from
Mar 16, 2022
Prev Previous commit
Next Next commit
use same endpoint for counting as for retrieving
  • Loading branch information
tgloeggl committed Mar 7, 2022
commit 87a5e7a92296f8c6582fcf65dd23693be7aabc81
29 changes: 22 additions & 7 deletions classes/OCRestClient/ApiEventsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,41 @@ public function setACL($episode_id, $acl)
*
* @return array response of episodes
*/
public function getBySeries($series_id, $params = [])
public function getBySeries($series_id)
{
static $events;
static $static_events;

if (empty($events[$series_id])) {
if (empty($static_events[$series_id])) {
$offset = Pager::getOffset();
$limit = Pager::getLimit();
$sort = Pager::getSortOrder();

$events = $this->getJSON('/?filter=is_part_of:' .
$series_id . ',status:EVENTS.EVENTS.STATUS.PROCESSED'
. "&withpublications=true&sort=$sort&limit=$limit&offset=$offset", $params);
$series_id . ',status:EVENTS.EVENTS.STATUS.PROCESSED,textFilter:engage-player'
. "&withpublications=true&sort=$sort&limit=$limit&offset=$offset");

$events[$series_id] = array_reduce($events, function ($events, $event) {
$static_events[$series_id] = array_reduce($events, function ($events, $event) {
$events[$event->identifier] = $event;
return $events;
}, []);
}

return $events[$series_id];
return $static_events[$series_id];
}

public function getEpisodeCount($series_id)
{
static $static_events;

if (empty($static_events[$series_id])) {
$events = $this->getJSON('/?filter=is_part_of:' .
$series_id . ',status:EVENTS.EVENTS.STATUS.PROCESSED,textFilter:engage-player'
. "&sort=&limit=9999&offset=0");

$static_events[$series_id] = sizeof($events);
}

return $static_events[$series_id];
}

public function getAllScheduledEvents()
Expand Down
22 changes: 0 additions & 22 deletions classes/OCRestClient/SearchClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,6 @@ public function getAllSeries()
}
}




// other functions

/**
* getEpisodeCount -
*
* @param string series_id Identifier for a Series
*
* @return int number of episodes
*/
public function getEpisodeCount($series_id)
{
if ($series = $this->getSeries($series_id)) {
$x = "search-results";
$count = $series->$x->total;

return intval($count);
}
}

public function getBaseURL()
{
$base = $this->base_url;
Expand Down
3 changes: 2 additions & 1 deletion controllers/course.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ public function index_action($active_id = 'false', $upload_message = false)
$this->search_client = SearchClient::getInstance();
$this->coursevis = $occourse->getSeriesVisibility();

Pager::setLength($this->search_client->getEpisodeCount($this->series_id));
$api_events = ApiEventsClient::getInstance();
Pager::setLength($api_events->getEpisodeCount($this->series_id));

$this->ordered_episode_ids = $this->get_ordered_episode_ids();

Expand Down