mirror of
https://github.com/flarum/core.git
synced 2025-08-02 14:37:49 +02:00
fix: unread filter gambit does not return results when > 999 read discussions for a user (#3295)
This commit is contained in:
@@ -42,16 +42,29 @@ class DiscussionRepository
|
|||||||
/**
|
/**
|
||||||
* Get the IDs of discussions which a user has read completely.
|
* Get the IDs of discussions which a user has read completely.
|
||||||
*
|
*
|
||||||
|
* @deprecated 1.3 Use `getReadIdsQuery` instead
|
||||||
|
*
|
||||||
* @param User $user
|
* @param User $user
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getReadIds(User $user)
|
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')
|
return Discussion::leftJoin('discussion_user', 'discussion_user.discussion_id', '=', 'discussions.id')
|
||||||
->where('discussion_user.user_id', $user->id)
|
->where('discussion_user.user_id', $user->id)
|
||||||
->whereColumn('last_read_post_number', '>=', 'last_post_number')
|
->whereColumn('last_read_post_number', '>=', 'last_post_number')
|
||||||
->pluck('id')
|
->select('id');
|
||||||
->all();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -61,7 +61,7 @@ class UnreadFilterGambit extends AbstractRegexGambit implements FilterInterface
|
|||||||
protected function constrain(Builder $query, User $actor, bool $negate)
|
protected function constrain(Builder $query, User $actor, bool $negate)
|
||||||
{
|
{
|
||||||
if ($actor->exists) {
|
if ($actor->exists) {
|
||||||
$readIds = $this->discussions->getReadIds($actor);
|
$readIds = $this->discussions->getReadIdsQuery($actor);
|
||||||
|
|
||||||
$query->where(function ($query) use ($readIds, $negate, $actor) {
|
$query->where(function ($query) use ($readIds, $negate, $actor) {
|
||||||
if (! $negate) {
|
if (! $negate) {
|
||||||
|
Reference in New Issue
Block a user