Skip to content

Commit 4645bf6

Browse files
authored
Merge pull request #206 from juresyahya/perf_improv
Performance Improvement when querying tags on model especially for models with lots of records and with tags
2 parents c3a299f + 758f551 commit 4645bf6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Taggable.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ public function scopeWithAllTags(Builder $query, $tagNames): Builder
205205
->where('tag_slug', TaggingUtility::normalize($tagSlug))
206206
->where('taggable_type', $className)
207207
->get()
208-
->pluck('taggable_id');
208+
->pluck('taggable_id')
209+
->unique();
209210

210211
$primaryKey = $this->getKeyName();
211212
$query->whereIn($this->getTable().'.'.$primaryKey, $tags);
@@ -401,7 +402,8 @@ private function assembleTagsForScoping($query, $tagNames)
401402
->whereIn('tag_slug', $tagNames)
402403
->where('taggable_type', $className)
403404
->get()
404-
->pluck('taggable_id');
405+
->pluck('taggable_id')
406+
->unique();
405407

406408
return $tags;
407409
}

0 commit comments

Comments
 (0)