···
-
func GetFollowerFollowingCount(e Execer, did string) (int, int, error) {
followers, following := 0, 0
···
COUNT(CASE WHEN user_did = ? THEN 1 END) AS following
FROM follows;`, did, did).Scan(&followers, &following)
-
return followers, following, nil
func GetFollows(e Execer, limit int, filters ...filter) ([]Follow, error) {
···
+
type FollowStats struct {
+
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)
+
return FollowStats{}, err
+
func GetFollowerFollowingCounts(e Execer, dids []string) (map[string]FollowStats, error) {
+
placeholders := make([]string, len(dids))
+
for i := range placeholders {
+
placeholderStr := strings.Join(placeholders, ",")
+
args := make([]any, len(dids)*2)
+
for i, did := range dids {
+
args[i+len(dids)] = did
+
coalesce(f.did, g.did) as did,
+
coalesce(f.followers, 0) as followers,
+
coalesce(g.following, 0) as following
+
select subject_did as did, count(*) as followers
+
where subject_did in (%s)
+
select user_did as did, count(*) as following
+
placeholderStr, placeholderStr)
+
result := make(map[string]FollowStats)
+
rows, err := e.Query(query, args...)
+
var followers, following int
+
if err := rows.Scan(&did, &followers, &following); err != nil {
+
result[did] = FollowStats{
+
for _, did := range dids {
+
if _, exists := result[did]; !exists {
+
result[did] = FollowStats{
func GetFollows(e Execer, limit int, filters ...filter) ([]Follow, error) {