aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillermo Serrahima <dev@vylion.com>2026-03-21 16:20:13 +0100
committerGuillermo Serrahima <dev@vylion.com>2026-03-21 16:20:13 +0100
commit7cd27b77a530f4daa291165d817d3961af8d70f6 (patch)
tree722535775e5aa5645d7b953eec7576c3985537f9
parent75f6db76bdbf8846b58d86951e0bebf8bd4b8a3a (diff)
downloadllostre-7cd27b77a530f4daa291165d817d3961af8d70f6.tar.xz
llostre-7cd27b77a530f4daa291165d817d3961af8d70f6.zip
Fixing thread deduplication
-rw-r--r--backend/notes/note.go17
1 files 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
}