Remove old read items

This commit is contained in:
Marcus Noble 2020-11-08 19:51:05 +00:00
parent 614264ebea
commit 4341529154
3 changed files with 14 additions and 0 deletions

View File

@ -23,6 +23,9 @@ func Refresh() error {
go RefreshFeed(feed.FeedURL)
}
fmt.Println("Reaping old items...")
feedStore.DeleteOldReadItems()
fmt.Printf("Going to sleep for %d minutes\n", interval)
time.Sleep(time.Duration(interval) * time.Minute)
}

View File

@ -1,6 +1,8 @@
package feeds
import (
"time"
"github.com/spf13/viper"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
@ -55,6 +57,14 @@ func (fs *FeedStore) GetUnread() *[]ItemWithFeed {
return items
}
func (fs *FeedStore) DeleteOldReadItems() {
t := time.Now()
threshold := t.Add(-time.Hour * 24 * 7)
fs.getDB().Table("items").
Where("read = ? and created < ?", true, threshold).
Delete(Item{})
}
func (fs *FeedStore) GetAll() *[]ItemWithFeed {
items := &[]ItemWithFeed{}
fs.getDB().Table("items").

View File

@ -46,6 +46,7 @@ type Item struct {
FeedID string
Read bool
Save bool
DeletedAt gorm.DeletedAt
}
type ItemWithFeed struct {