Remove old read items
This commit is contained in:
parent
614264ebea
commit
4341529154
@ -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)
|
||||
}
|
||||
|
@ -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").
|
||||
|
@ -46,6 +46,7 @@ type Item struct {
|
||||
FeedID string
|
||||
Read bool
|
||||
Save bool
|
||||
DeletedAt gorm.DeletedAt
|
||||
}
|
||||
|
||||
type ItemWithFeed struct {
|
||||
|
Loading…
Reference in New Issue
Block a user