From f19ab21b7d7dcddb3de0536c272cb22d581eb8d7 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sat, 19 May 2018 16:40:24 -0700 Subject: Archive read entries automatically after 60 days --- storage/entry.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'storage') diff --git a/storage/entry.go b/storage/entry.go index fb1fb59..65c0220 100644 --- a/storage/entry.go +++ b/storage/entry.go @@ -176,6 +176,19 @@ func (s *Storage) cleanupEntries(feedID int64, entryHashes []string) error { return nil } +// ArchiveEntries changes the status of read items to "removed" after 60 days. +func (s *Storage) ArchiveEntries() error { + query := ` + UPDATE entries SET status='removed' + WHERE id=ANY(SELECT id FROM entries WHERE status='read' AND starred is false AND published_at < now () - '60 days'::interval LIMIT 500) + ` + if _, err := s.db.Exec(query); err != nil { + return fmt.Errorf("unable to archive read entries: %v", err) + } + + return nil +} + // SetEntriesStatus update the status of the given list of entries. func (s *Storage) SetEntriesStatus(userID int64, entryIDs []int64, status string) error { defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:SetEntriesStatus] userID=%d, entryIDs=%v, status=%s", userID, entryIDs, status)) -- cgit v1.2.3