From 4aee139f6cc579588d0929c3a26de43900540d71 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 5 Feb 2023 17:04:15 -0300 Subject: [PATCH] modify AppendUnique so it matches only the first two items. --- tags.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tags.go b/tags.go index 2dd5ed8..f1d1c09 100644 --- a/tags.go +++ b/tags.go @@ -99,9 +99,15 @@ func (tags Tags) FilterOut(tagPrefix []string) Tags { return filtered } -// AppendUnique appends a tag if it doesn't exist yet, otherwise does nothing +// AppendUnique appends a tag if it doesn't exist yet, otherwise does nothing. +// the uniqueness comparison is done based only on the first 2 elements of the tag. func (tags Tags) AppendUnique(tag Tag) Tags { - if tags.GetFirst(tag) == nil { + n := len(tag) + if n > 2 { + n = 2 + } + + if tags.GetFirst(tag[:n]) == nil { return append(tags, tag) } else { return tags