1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-26 18:21:01 +00:00

perf(storage): pair all SELECT true with LIMIT 1

Apparently, postgresql isn't smart enough to realize that once a true value
value is found as part of a `SELECT true`, there is no need to scan the rest of
the table, so we have to make this explicit. We could also have used the
`SELECT EXISTS(…)` construct, but it's more verbose and I don't like it.
This commit is contained in:
jvoisin 2025-08-02 22:01:30 +02:00 committed by Frédéric Guillot
parent 2e28bf78bd
commit 546fbcff8f
6 changed files with 14 additions and 14 deletions

View file

@ -31,7 +31,7 @@ func (s *Storage) CategoryTitleExists(userID int64, title string) bool {
// CategoryIDExists checks if the given category exists into the database.
func (s *Storage) CategoryIDExists(userID, categoryID int64) bool {
var result bool
query := `SELECT true FROM categories WHERE user_id=$1 AND id=$2`
query := `SELECT true FROM categories WHERE user_id=$1 AND id=$2 LIMIT 1`
s.db.QueryRow(query, userID, categoryID).Scan(&result)
return result
}