Skip to content

Commit

Permalink
Limited history to max 99 elements, removed a var dump
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgrayisok committed Jan 10, 2019
1 parent 3aef3d2 commit 4c2e426
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/behaviors/RecentlyViewedBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public function beforePrepare(): bool
$allCases .= 'WHEN elements.id=' . $anId . ' THEN ' . $count . ' ';
$count++;
}
var_dump($allCases);
$this->owner->subQuery->orderBy([new \yii\db\Expression(
'CASE ' . $allCases . ' END'
)]);
Expand Down
5 changes: 5 additions & 0 deletions src/services/Queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
class Queries extends Component
{

private $maxRecentHistory = 99;

public function clear()
{
Craft::$app->getSession()->set('rv-recent-ids', []);
Expand All @@ -60,6 +62,9 @@ public function trackId($id)
unset($recentIds[$key]);
}
$recentIds[] = $id;
if(sizeof($recentIds) > $this->maxRecentHistory){
$recentIds = array_slice($recentIds, - $this->maxRecentHistory);
}
Craft::$app->getSession()->set('rv-recent-ids', $recentIds);
}
}
Expand Down

0 comments on commit 4c2e426

Please sign in to comment.