···
58
-
func GetFollowerFollowingCount(e Execer, did string) (int, int, error) {
58
+
type FollowStats struct {
63
+
func GetFollowerFollowingCount(e Execer, did string) (FollowStats, error) {
followers, following := 0, 0
···
COUNT(CASE WHEN user_did = ? THEN 1 END) AS following
FROM follows;`, did, did).Scan(&followers, &following)
71
+
return FollowStats{}, err
74
+
Followers: followers,
75
+
Following: following,
79
+
func GetFollowerFollowingCounts(e Execer, dids []string) (map[string]FollowStats, error) {
84
+
placeholders := make([]string, len(dids))
85
+
for i := range placeholders {
86
+
placeholders[i] = "?"
68
-
return followers, following, nil
88
+
placeholderStr := strings.Join(placeholders, ",")
90
+
args := make([]any, len(dids)*2)
91
+
for i, did := range dids {
93
+
args[i+len(dids)] = did
96
+
query := fmt.Sprintf(`
98
+
coalesce(f.did, g.did) as did,
99
+
coalesce(f.followers, 0) as followers,
100
+
coalesce(g.following, 0) as following
102
+
select subject_did as did, count(*) as followers
104
+
where subject_did in (%s)
105
+
group by subject_did
108
+
select user_did as did, count(*) as following
110
+
where user_did in (%s)
112
+
) g on f.did = g.did`,
113
+
placeholderStr, placeholderStr)
115
+
result := make(map[string]FollowStats)
117
+
rows, err := e.Query(query, args...)
125
+
var followers, following int
126
+
if err := rows.Scan(&did, &followers, &following); err != nil {
129
+
result[did] = FollowStats{
130
+
Followers: followers,
131
+
Following: following,
135
+
for _, did := range dids {
136
+
if _, exists := result[did]; !exists {
137
+
result[did] = FollowStats{
func GetFollows(e Execer, limit int, filters ...filter) ([]Follow, error) {