mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-17 10:56:24 -07:00
Remove need for SQL grouping (pain in the ass in Postgres)
This commit is contained in:
parent
8a73e1aa13
commit
0113d972d4
3 changed files with 16 additions and 10 deletions
|
@ -92,6 +92,9 @@ func BuildBoardPages(board *gcsql.Board) error {
|
|||
Caller().Msg("Failed getting replies")
|
||||
return errors.New("Failed getting replies: " + err.Error())
|
||||
}
|
||||
if len(catalogThread.Posts) == 0 {
|
||||
continue
|
||||
}
|
||||
if len(catalogThread.Posts) > maxRepliesOnBoardPage {
|
||||
op := catalogThread.Posts[0]
|
||||
replies := catalogThread.Posts[len(catalogThread.Posts)-maxRepliesOnBoardPage:]
|
||||
|
|
|
@ -34,7 +34,13 @@ func getRecentPosts() ([]recentPost, error) {
|
|||
DBPREFIXposts.id,
|
||||
DBPREFIXposts.message_raw,
|
||||
(SELECT dir FROM DBPREFIXboards WHERE id = t.board_id) AS dir,
|
||||
f.filename, op.id
|
||||
COALESCE(
|
||||
(SELECT filename FROM DBPREFIXfiles WHERE DBPREFIXfiles.post_id = DBPREFIXposts.id`
|
||||
if !siteCfg.RecentPostsWithNoFile {
|
||||
query += ` AND filename != '' AND filename != 'deleted'`
|
||||
}
|
||||
query += ` ORDER BY DBPREFIXfiles.id DESC LIMIT 1), ''),
|
||||
op.id
|
||||
FROM
|
||||
DBPREFIXposts
|
||||
LEFT JOIN (
|
||||
|
@ -47,10 +53,8 @@ func getRecentPosts() ([]recentPost, error) {
|
|||
SELECT id, thread_id FROM DBPREFIXposts WHERE is_top_post
|
||||
) op ON op.thread_id = DBPREFIXposts.thread_id
|
||||
WHERE DBPREFIXposts.is_deleted = FALSE`
|
||||
if !siteCfg.RecentPostsWithNoFile {
|
||||
query += ` AND f.filename != '' AND f.filename != 'deleted'`
|
||||
}
|
||||
query += " GROUP BY DBPREFIXposts.id LIMIT " + strconv.Itoa(siteCfg.MaxRecentPosts)
|
||||
|
||||
query += " LIMIT " + strconv.Itoa(siteCfg.MaxRecentPosts)
|
||||
rows, err := gcsql.QuerySQL(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -112,7 +112,7 @@ func (p Post) UploadPath() string {
|
|||
}
|
||||
|
||||
func GetBuildablePost(id int, boardid int) (*Post, error) {
|
||||
const query = postQueryBase + " AND DBPREFIXposts.id = ? GROUP BY DBPREFIXposts.id"
|
||||
const query = postQueryBase + " AND DBPREFIXposts.id = ?"
|
||||
var post Post
|
||||
var threadID int
|
||||
err := gcsql.QueryRowSQL(query, []interface{}{id}, []interface{}{
|
||||
|
@ -134,7 +134,6 @@ func GetBuildablePostsByIP(ip string, limit int) ([]Post, error) {
|
|||
if limit > 0 {
|
||||
query += " LIMIT " + strconv.Itoa(limit)
|
||||
}
|
||||
query += " GROUP BY DBPREFIXposts.id"
|
||||
rows, err := gcsql.QuerySQL(query, ip)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -160,7 +159,7 @@ func GetBuildablePostsByIP(ip string, limit int) ([]Post, error) {
|
|||
}
|
||||
|
||||
func getBoardTopPosts(boardID int) ([]Post, error) {
|
||||
const query = postQueryBase + " AND is_top_post AND t.board_id = ? GROUP BY DBPREFIXposts.id"
|
||||
const query = postQueryBase + " AND is_top_post AND t.board_id = ?"
|
||||
rows, err := gcsql.QuerySQL(query, boardID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -186,7 +185,7 @@ func getBoardTopPosts(boardID int) ([]Post, error) {
|
|||
}
|
||||
|
||||
func getThreadPosts(thread *gcsql.Thread) ([]Post, error) {
|
||||
const query = postQueryBase + " AND DBPREFIXposts.thread_id = ? GROUP BY DBPREFIXposts.id"
|
||||
const query = postQueryBase + " AND DBPREFIXposts.thread_id = ?"
|
||||
rows, err := gcsql.QuerySQL(query, thread.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -220,7 +219,7 @@ func GetRecentPosts(boardid int, limit int) ([]Post, error) {
|
|||
args = append(args, boardid)
|
||||
}
|
||||
|
||||
query += " ORDER BY DBPREFIXposts.id DESC LIMIT " + strconv.Itoa(limit) + " GROUP BY DBPREFIXposts.id"
|
||||
query += " ORDER BY DBPREFIXposts.id DESC LIMIT " + strconv.Itoa(limit)
|
||||
rows, err := gcsql.QuerySQL(query, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue