Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
Use more efficient query
Browse files Browse the repository at this point in the history
  • Loading branch information
tbg committed Mar 14, 2016
1 parent 991ed04 commit c595ef6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions photos/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,10 @@ func listComments(tx *sql.Tx, userID int, commentIDs *[][]byte) ([]byte, error)
if err != nil {
return nil, err
}
const selectSQL = `
SELECT commentID, userID, message, timestamp FROM comments WHERE photoID = $1 ORDER BY timestamp DESC LIMIT 100`
const selectSQL = `SELECT commentID, userID, message, timestamp FROM comments ` +
`WHERE photoID = $1 AND commentID IN ` +
`(SELECT commentID FROM comments WHERE photoID = $1 ORDER BY timestamp DESC LIMIT 100)` +
`ORDER BY timestamp DESC`
rows, err := tx.Query(selectSQL, photoID)
switch {
case err == sql.ErrNoRows:
Expand Down

0 comments on commit c595ef6

Please sign in to comment.