Skip to content

Commit

Permalink
Update Lists.php
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdullahGhanem authored Dec 3, 2022
1 parent 4e1b746 commit 13381ab
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Traits/Lists.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@

trait Lists
{
/**
* Fetch all time trending subjects Ids.
*
* @param int $limit
* @param array $constraints optional. filter models by attributes (where=[...])
* @return array
*/
public function topIds($limit = 5, $orderByAsc = false, $constraints = [])
{
if(is_array($orderByAsc)) {
$constraints = $orderByAsc;
$orderByAsc = false;
}

$cacheKey = $this->keys->cache($limit, $orderByAsc, $constraints);

$cachedList = $this->cachedList($limit, $cacheKey);
return $this->getVisitsIds($limit, $this->keys->visits, $orderByAsc);
}

/**
* Fetch all time trending subjects.
*
Expand Down Expand Up @@ -71,6 +91,19 @@ protected function getSortedList($name, $limit, $orderByAsc = false, $withValues
return $this->connection->valueList($this->keys->visits . "_{$name}:{$this->keys->id}", $limit, $orderByAsc, $withValues);
}


/**
* Fetch lowest subjects Ids.
*
* @param int $limit
* @param array $constraints optional
* @return array
*/
public function lowIds($limit = 5, $constraints = [])
{
return $this->topIds($limit, true, $constraints);
}

/**
* Fetch lowest subjects.
*
Expand Down

0 comments on commit 13381ab

Please sign in to comment.