Skip to content

Commit

Permalink
fix: unread filter gambit does not return results when > 999 read dis…
Browse files Browse the repository at this point in the history
…cussions for a user (#3295)
  • Loading branch information
imorland authored Mar 9, 2022
1 parent 9b302a1 commit 5045254
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/Discussion/DiscussionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,29 @@ public function findOrFail($id, User $user = null)
/**
* Get the IDs of discussions which a user has read completely.
*
* @deprecated 1.3 Use `getReadIdsQuery` instead
*
* @param User $user
* @return array
*/
public function getReadIds(User $user)
{
return $this->getReadIdsQuery($user)
->all();
}

/**
* Get a query containing the IDs of discussions which a user has read completely.
*
* @param User $user
* @return Builder
*/
public function getReadIdsQuery(User $user): Builder
{
return Discussion::leftJoin('discussion_user', 'discussion_user.discussion_id', '=', 'discussions.id')
->where('discussion_user.user_id', $user->id)
->whereColumn('last_read_post_number', '>=', 'last_post_number')
->pluck('id')
->all();
->select('id');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Discussion/Query/UnreadFilterGambit.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function filter(FilterState $filterState, string $filterValue, bool $nega
protected function constrain(Builder $query, User $actor, bool $negate)
{
if ($actor->exists) {
$readIds = $this->discussions->getReadIds($actor);
$readIds = $this->discussions->getReadIdsQuery($actor);

$query->where(function ($query) use ($readIds, $negate, $actor) {
if (! $negate) {
Expand Down

0 comments on commit 5045254

Please sign in to comment.