1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-11 17:51: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

@ -13,7 +13,7 @@ import (
// HasDuplicateFeverUsername checks if another user have the same Fever username.
func (s *Storage) HasDuplicateFeverUsername(userID int64, feverUsername string) bool {
query := `SELECT true FROM integrations WHERE user_id != $1 AND fever_username=$2`
query := `SELECT true FROM integrations WHERE user_id != $1 AND fever_username=$2 LIMIT 1`
var result bool
s.db.QueryRow(query, userID, feverUsername).Scan(&result)
return result
@ -21,7 +21,7 @@ func (s *Storage) HasDuplicateFeverUsername(userID int64, feverUsername string)
// HasDuplicateGoogleReaderUsername checks if another user have the same Google Reader username.
func (s *Storage) HasDuplicateGoogleReaderUsername(userID int64, googleReaderUsername string) bool {
query := `SELECT true FROM integrations WHERE user_id != $1 AND googlereader_username=$2`
query := `SELECT true FROM integrations WHERE user_id != $1 AND googlereader_username=$2 LIMIT 1`
var result bool
s.db.QueryRow(query, userID, googleReaderUsername).Scan(&result)
return result