Optimize catalog view

This commit is contained in:
Dominic Ferrando
2025-04-19 14:47:11 -04:00
parent 39c5b41657
commit 399d2b969d
2 changed files with 23 additions and 7 deletions
+8 -6
View File
@@ -235,24 +235,26 @@ func main() {
previews := make([]views.CatalogThreadPreview, 0, len(threads))
for _, thread := range threads {
posts, err := database.GetPosts(db, thread.Id)
op, err := database.GetOriginalPost(db, thread.Id)
if err != nil {
http.Error(w, "Failed to get posts", http.StatusBadRequest)
log.Printf("GetPosts: %v", err)
log.Printf("GetOriginalPost: %v", err)
return
}
if len(posts) == 0 || posts[0].MediaPath == "" {
log.Printf("OP: %+v", op)
if op.MediaPath == "" {
http.Error(w, "Malformed thread", http.StatusInternalServerError)
log.Printf("Thread %d has no posts or no OP image", thread.Id)
log.Printf("Thread %d has no OP image", thread.Id)
return
}
previews = append(previews, views.CatalogThreadPreview{
Subject: thread.Subject,
Body: posts[0].Body,
Body: op.Body,
ThreadURL: fmt.Sprintf("/%s/threads/%d", slug, thread.Id),
MediaPath: posts[0].MediaPath,
MediaPath: op.MediaPath,
})
}