mirror of
https://github.com/miniflux/v2.git
synced 2025-08-16 18:01:37 +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
|
@ -226,7 +226,7 @@ func (s *Storage) entryExists(tx *sql.Tx, entry *model.Entry) (bool, error) {
|
|||
var result bool
|
||||
|
||||
// Note: This query uses entries_feed_id_hash_key index (filtering on user_id is not necessary).
|
||||
err := tx.QueryRow(`SELECT true FROM entries WHERE feed_id=$1 AND hash=$2`, entry.FeedID, entry.Hash).Scan(&result)
|
||||
err := tx.QueryRow(`SELECT true FROM entries WHERE feed_id=$1 AND hash=$2 LIMIT 1`, entry.FeedID, entry.Hash).Scan(&result)
|
||||
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return result, fmt.Errorf(`store: unable to check if entry exists: %v`, err)
|
||||
|
@ -237,7 +237,7 @@ func (s *Storage) entryExists(tx *sql.Tx, entry *model.Entry) (bool, error) {
|
|||
|
||||
func (s *Storage) IsNewEntry(feedID int64, entryHash string) bool {
|
||||
var result bool
|
||||
s.db.QueryRow(`SELECT true FROM entries WHERE feed_id=$1 AND hash=$2`, feedID, entryHash).Scan(&result)
|
||||
s.db.QueryRow(`SELECT true FROM entries WHERE feed_id=$1 AND hash=$2 LIMIT 1`, feedID, entryHash).Scan(&result)
|
||||
return !result
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue