This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

appview/db: query distinct follow rows on query

We keep duplicated follow records in db to delete them on unfollow. So
instead of having unique constraint, we deduplicate them on query.

Signed-off-by: Seongmin Lee <git@boltless.me>

author
Seongmin Lee
committer
Tangled
date (Jul 17, 2026, 6:25 PM +0300) commit 49add549 parent 7b0f21f2 change-id ksoylnkv
+5 -5
+5 -5
appview/db/follow.go
··· 60 60 // GetMostFollowed returns the DIDs with the most followers, most-followed first. 61 61 func GetMostFollowed(e Execer, limit int) ([]string, error) { 62 62 query := ` 63 - select subject_did, count(*) as followers 63 + select subject_did, count(distinct did) as followers 64 64 from follows 65 65 group by subject_did 66 66 order by followers desc ··· 88 88 var followers, following int64 89 89 err := e.QueryRow( 90 90 `SELECT 91 - COUNT(CASE WHEN subject_did = ? THEN 1 END) AS followers, 92 - COUNT(CASE WHEN did = ? THEN 1 END) AS following 91 + COUNT(DISTINCT CASE WHEN subject_did = ? THEN did END) AS followers, 92 + COUNT(DISTINCT CASE WHEN did = ? THEN subject_did END) AS following 93 93 FROM follows;`, did, did).Scan(&followers, &following) 94 94 if err != nil { 95 95 return models.FollowStats{}, err ··· 123 123 coalesce(f.followers, 0) as followers, 124 124 coalesce(g.following, 0) as following 125 125 from ( 126 - select subject_did as did, count(*) as followers 126 + select subject_did as did, count(distinct did) as followers 127 127 from follows 128 128 where subject_did in (%s) 129 129 group by subject_did 130 130 ) f 131 131 full outer join ( 132 - select did as did, count(*) as following 132 + select did as did, count(distinct subject_did) as following 133 133 from follows 134 134 where did in (%s) 135 135 group by did