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 f123170
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions photos/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,11 @@ func listPhotos(tx *sql.Tx, userID int, photoIDs *[][]byte) error {
if err != nil {
return err
}
const selectSQL = `
SELECT id, caption, commentCount, latitude, longitude, timestamp FROM photos WHERE userID = $1 ORDER BY timestamp DESC LIMIT 100`
const selectSQL = `SELECT commentID, userID, message, timestamp FROM comments ` +
`WHERE photoID = $1::bytea AND commentID IN ` +
`(SELECT commentID FROM comments WHERE photoID = $1::bytea ORDER BY timestamp DESC LIMIT 100)` +
`ORDER BY timestamp DESC`

rows, err := tx.Query(selectSQL, userID)
switch {
case err == sql.ErrNoRows:
Expand Down

0 comments on commit f123170

Please sign in to comment.