This commit is contained in:
Eirik Øverby 2025-06-05 00:51:11 +00:00 committed by GitHub
commit 3a66716fad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2044,7 +2044,7 @@ func (db *datastore) GetTopPosts(u *User, alias string, hostName string) (*[]Pub
where = " AND alias = ?" where = " AND alias = ?"
params = append(params, 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 { if err != nil {
log.Error("Failed selecting from posts: %v", err) log.Error("Failed selecting from posts: %v", err)
return nil, impart.HTTPError{http.StatusInternalServerError, "Couldn't retrieve user top posts."} 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{} c := Collection{}
var alias, title, description sql.NullString var alias, title, description sql.NullString
var views sql.NullInt64 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 { if err != nil {
log.Error("Failed scanning User.getPosts() row: %v", err) log.Error("Failed scanning User.getPosts() row: %v", err)
gotErr = true gotErr = true