From 758f55122d67523b5cb61ad91f9379ebb1bd7e8e Mon Sep 17 00:00:00 2001 From: Jures Yahya Date: Mon, 28 Mar 2022 12:18:43 +0800 Subject: [PATCH] add perf improvement when getting tags --- src/Taggable.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Taggable.php b/src/Taggable.php index 2408f86..652b1c3 100644 --- a/src/Taggable.php +++ b/src/Taggable.php @@ -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); @@ -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; }