From 7cd27b77a530f4daa291165d817d3961af8d70f6 Mon Sep 17 00:00:00 2001 From: Guillermo Serrahima Date: Sat, 21 Mar 2026 16:20:13 +0100 Subject: Fixing thread deduplication --- backend/notes/note.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/backend/notes/note.go b/backend/notes/note.go index c427a8f..8a73b70 100644 --- a/backend/notes/note.go +++ b/backend/notes/note.go @@ -35,23 +35,22 @@ func MissingNote(uri string) *Note { } } -func isChainContained(smallChain, bigChain []Note) bool { - if len(smallChain) > len(bigChain) { +func isChainContained(smallChainPost, bigChainPost Note) bool { + if len(smallChainPost.Parents) > len(bigChainPost.Parents) { return false } - // check if smallChain is a suffix of bigChain - offset := len(bigChain) - len(smallChain) - for i, note := range smallChain { - if bigChain[offset+i].URI != note.URI { + // check if parents of smallChainPost are included in bigChainPost + offset := len(bigChainPost.Parents) - len(smallChainPost.Parents) + for i, note := range smallChainPost.Parents { + if bigChainPost.Parents[offset+i].URI != note.URI { return false } } - return true + return smallChainPost.URI == bigChainPost.Parents[offset-1].URI } func DeduplicateThreads(posts []Note) []Note { - // sort by parent chain length (longest first) sort.Slice(posts, func(i, j int) bool { return len(posts[i].Parents) > len(posts[j].Parents) }) @@ -61,7 +60,7 @@ func DeduplicateThreads(posts []Note) []Note { isRedundant := false for _, kept := range filtered { // check if this post's chain is contained in any kept post - if isChainContained(post.Parents, kept.Parents) && post.URI == kept.URI { + if isChainContained(post, kept) { isRedundant = true break } -- cgit v1.2.3