1
0
Fork 0
forked from mirror/pixelfed

Update SearchApiV2Service, improve query performance

This commit is contained in:
Daniel Supernault 2022-12-31 06:28:17 -07:00
parent e0c3dae324
commit 4d1f281144
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -87,7 +87,7 @@ class SearchApiV2Service
$limit = $this->query->input('limit') ?? 20; $limit = $this->query->input('limit') ?? 20;
$offset = $this->query->input('offset') ?? 0; $offset = $this->query->input('offset') ?? 0;
$rawQuery = $initalQuery ? $initalQuery : $this->query->input('q'); $rawQuery = $initalQuery ? $initalQuery : $this->query->input('q');
$query = '%' . $rawQuery . '%'; $query = $rawQuery . '%';
if(Str::substrCount($rawQuery, '@') >= 1 && Str::contains($rawQuery, config('pixelfed.domain.app'))) { if(Str::substrCount($rawQuery, '@') >= 1 && Str::contains($rawQuery, config('pixelfed.domain.app'))) {
$deliminatorCount = Str::substrCount($rawQuery, '@'); $deliminatorCount = Str::substrCount($rawQuery, '@');
$query = explode('@', $rawQuery)[$deliminatorCount == 1 ? 0 : 1]; $query = explode('@', $rawQuery)[$deliminatorCount == 1 ? 0 : 1];
@ -123,7 +123,7 @@ class SearchApiV2Service
$mastodonMode = self::$mastodonMode; $mastodonMode = self::$mastodonMode;
$limit = $this->query->input('limit') ?? 20; $limit = $this->query->input('limit') ?? 20;
$offset = $this->query->input('offset') ?? 0; $offset = $this->query->input('offset') ?? 0;
$query = '%' . $this->query->input('q') . '%'; $query = $this->query->input('q') . '%';
return Hashtag::where('can_search', true) return Hashtag::where('can_search', true)
->where('name', 'like', $query) ->where('name', 'like', $query)
->offset($offset) ->offset($offset)