Simplify cleanupEntries' query

- `NOT (hash=ANY(%4))` can be expressed as `hash NOT IN $4`
- There is no need for a subquery operating on the same table,
  moving the conditions out is equivalent.
This commit is contained in:
jvoisin 2024-02-25 16:52:08 +01:00 committed by Frédéric Guillot
parent ccd3955bf4
commit 26d189917e

View file

@ -251,11 +251,11 @@ func (s *Storage) cleanupEntries(feedID int64, entryHashes []string) error {
DELETE FROM
entries
WHERE
feed_id=$1
AND
id IN (SELECT id FROM entries WHERE feed_id=$2 AND status=$3 AND NOT (hash=ANY($4)))
feed_id=$1 AND
status=$3 AND
NOT (hash=ANY($4))
`
if _, err := s.db.Exec(query, feedID, feedID, model.EntryStatusRemoved, pq.Array(entryHashes)); err != nil {
if _, err := s.db.Exec(query, feedID, model.EntryStatusRemoved, pq.Array(entryHashes)); err != nil {
return fmt.Errorf(`store: unable to cleanup entries: %v`, err)
}