Fixes #1877 Replace getIdsForUsername() with subquery instead. (#1878)

This commit is contained in:
Tariq Hussein 2019-10-02 00:04:01 +01:00 committed by Daniël Klabbers
parent 23709a77a2
commit 5dbe97630c

View File

@ -28,15 +28,25 @@ class FulltextGambit implements GambitInterface
$this->users = $users;
}
/**
* @param $searchValue
* @return \Illuminate\Database\Eloquent\Builder
*/
private function getUserSearchSubQuery($searchValue)
{
return $this->users
->query()
->select('id')
->where('username', 'like', "{$searchValue}%");
}
/**
* {@inheritdoc}
*/
public function apply(AbstractSearch $search, $bit)
public function apply(AbstractSearch $search, $searchValue)
{
$users = $this->users->getIdsForUsername($bit, $search->getActor());
$search->getQuery()->whereIn('id', $users);
$search->setDefaultSort(['id' => $users]);
$search->getQuery()
->whereIn('id',
$this->getUserSearchSubQuery($searchValue));
}
}