From 623201588e2d5f1e09f76877047e79b0a20f7ee9 Mon Sep 17 00:00:00 2001 From: ltning <> Date: Sat, 3 May 2025 14:19:40 +0000 Subject: [PATCH] Fix like counts on stats page --- database.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database.go b/database.go index 84898e0..4aac01d 100644 --- a/database.go +++ b/database.go @@ -2044,7 +2044,7 @@ func (db *datastore) GetTopPosts(u *User, alias string, hostName string) (*[]Pub where = " AND alias = ?" params = append(params, alias) } - rows, err := db.Query("SELECT p.id, p.slug, p.view_count, p.title, p.content, c.alias, c.title, c.description, c.view_count FROM posts p LEFT JOIN collections c ON p.collection_id = c.id WHERE p.owner_id = ?"+where+" ORDER BY p.view_count DESC, created DESC LIMIT 25", params...) + rows, err := db.Query("SELECT p.id, p.slug, p.view_count, p.title, p.content, c.alias, c.title, c.description, c.view_count, count(*) like_count FROM posts p LEFT JOIN collections c ON p.collection_id = c.id LEFT JOIN remote_likes l ON p.id=l.post_id WHERE p.owner_id = ?"+where+" GROUP BY p.id ORDER BY p.view_count, like_count DESC, p.created DESC LIMIT 25", params...) if err != nil { log.Error("Failed selecting from posts: %v", err) return nil, impart.HTTPError{http.StatusInternalServerError, "Couldn't retrieve user top posts."} @@ -2058,7 +2058,7 @@ func (db *datastore) GetTopPosts(u *User, alias string, hostName string) (*[]Pub c := Collection{} var alias, title, description sql.NullString var views sql.NullInt64 - err = rows.Scan(&p.ID, &p.Slug, &p.ViewCount, &p.Title, &p.Content, &alias, &title, &description, &views) + err = rows.Scan(&p.ID, &p.Slug, &p.ViewCount, &p.Title, &p.Content, &alias, &title, &description, &views, &p.LikeCount) if err != nil { log.Error("Failed scanning User.getPosts() row: %v", err) gotErr = true