Skip to content

Commit

Permalink
Merge pull request #206 from juresyahya/perf_improv
Browse files Browse the repository at this point in the history
Performance Improvement when querying tags on model especially for models with lots of records and with tags
  • Loading branch information
rtconner committed Mar 28, 2022
2 parents c3a299f + 758f551 commit 4645bf6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Taggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ public function scopeWithAllTags(Builder $query, $tagNames): Builder
->where('tag_slug', TaggingUtility::normalize($tagSlug))
->where('taggable_type', $className)
->get()
->pluck('taggable_id');
->pluck('taggable_id')
->unique();

$primaryKey = $this->getKeyName();
$query->whereIn($this->getTable().'.'.$primaryKey, $tags);
Expand Down Expand Up @@ -401,7 +402,8 @@ private function assembleTagsForScoping($query, $tagNames)
->whereIn('tag_slug', $tagNames)
->where('taggable_type', $className)
->get()
->pluck('taggable_id');
->pluck('taggable_id')
->unique();

return $tags;
}
Expand Down

0 comments on commit 4645bf6

Please sign in to comment.