1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-09-15 18:57:04 +00:00

Add option to archive unread entries

This commit is contained in:
Frédéric Guillot 2020-09-12 20:04:06 -07:00
parent df7a6e18fd
commit 13c89c29c5
6 changed files with 44 additions and 66 deletions

View file

@ -209,26 +209,32 @@ func (s *Storage) UpdateEntries(userID, feedID int64, entries model.Entries, upd
return nil
}
// ArchiveEntries changes the status of read items to "removed" after specified days.
func (s *Storage) ArchiveEntries(days int) error {
// ArchiveEntries changes the status of entries to "removed" after the given number of days.
func (s *Storage) ArchiveEntries(status string, days int) (int64, error) {
if days < 0 {
return nil
return 0, nil
}
before := time.Now().AddDate(0, 0, -days)
query := `
UPDATE
entries
SET
status=$1
status='removed'
WHERE
id=ANY(SELECT id FROM entries WHERE status=$2 AND starred is false AND share_code='' AND published_at < $3 LIMIT 5000)
id=ANY(SELECT id FROM entries WHERE status=$1 AND starred is false AND share_code='' AND published_at < now () - '%d days'::interval LIMIT 5000)
`
if _, err := s.db.Exec(query, model.EntryStatusRemoved, model.EntryStatusRead, before); err != nil {
return fmt.Errorf(`store: unable to archive read entries: %v`, err)
result, err := s.db.Exec(fmt.Sprintf(query, days), status)
if err != nil {
return 0, fmt.Errorf(`store: unable to archive %s entries: %v`, status, err)
}
return nil
count, err := result.RowsAffected()
if err != nil {
return 0, fmt.Errorf(`store: unable to get the number of rows affected: %v`, err)
}
return count, nil
}
// SetEntriesStatus update the status of the given list of entries.