mirror of
https://github.com/miniflux/v2.git
synced 2025-08-31 18:31: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:
parent
2e28bf78bd
commit
546fbcff8f
6 changed files with 14 additions and 14 deletions
|
@ -35,7 +35,7 @@ func (l byStateAndName) Less(i, j int) bool {
|
|||
// FeedExists checks if the given feed exists.
|
||||
func (s *Storage) FeedExists(userID, feedID int64) bool {
|
||||
var result bool
|
||||
query := `SELECT true FROM feeds WHERE user_id=$1 AND id=$2`
|
||||
query := `SELECT true FROM feeds WHERE user_id=$1 AND id=$2 LIMIT 1`
|
||||
s.db.QueryRow(query, userID, feedID).Scan(&result)
|
||||
return result
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ func (s *Storage) FeedExists(userID, feedID int64) bool {
|
|||
// CategoryFeedExists returns true if the given feed exists that belongs to the given category.
|
||||
func (s *Storage) CategoryFeedExists(userID, categoryID, feedID int64) bool {
|
||||
var result bool
|
||||
query := `SELECT true FROM feeds WHERE user_id=$1 AND category_id=$2 AND id=$3`
|
||||
query := `SELECT true FROM feeds WHERE user_id=$1 AND category_id=$2 AND id=$3 LIMIT 1`
|
||||
s.db.QueryRow(query, userID, categoryID, feedID).Scan(&result)
|
||||
return result
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ func (s *Storage) CategoryFeedExists(userID, categoryID, feedID int64) bool {
|
|||
// FeedURLExists checks if feed URL already exists.
|
||||
func (s *Storage) FeedURLExists(userID int64, feedURL string) bool {
|
||||
var result bool
|
||||
query := `SELECT true FROM feeds WHERE user_id=$1 AND feed_url=$2`
|
||||
query := `SELECT true FROM feeds WHERE user_id=$1 AND feed_url=$2 LIMIT 1`
|
||||
s.db.QueryRow(query, userID, feedURL).Scan(&result)
|
||||
return result
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ func (s *Storage) FeedURLExists(userID int64, feedURL string) bool {
|
|||
// AnotherFeedURLExists checks if the user a duplicated feed.
|
||||
func (s *Storage) AnotherFeedURLExists(userID, feedID int64, feedURL string) bool {
|
||||
var result bool
|
||||
query := `SELECT true FROM feeds WHERE id <> $1 AND user_id=$2 AND feed_url=$3`
|
||||
query := `SELECT true FROM feeds WHERE id <> $1 AND user_id=$2 AND feed_url=$3 LIMIT 1`
|
||||
s.db.QueryRow(query, feedID, userID, feedURL).Scan(&result)
|
||||
return result
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue