Remove old read items
This commit is contained in:
parent
614264ebea
commit
4341529154
@ -23,6 +23,9 @@ func Refresh() error {
|
|||||||
go RefreshFeed(feed.FeedURL)
|
go RefreshFeed(feed.FeedURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("Reaping old items...")
|
||||||
|
feedStore.DeleteOldReadItems()
|
||||||
|
|
||||||
fmt.Printf("Going to sleep for %d minutes\n", interval)
|
fmt.Printf("Going to sleep for %d minutes\n", interval)
|
||||||
time.Sleep(time.Duration(interval) * time.Minute)
|
time.Sleep(time.Duration(interval) * time.Minute)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package feeds
|
package feeds
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"gorm.io/driver/sqlite"
|
"gorm.io/driver/sqlite"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@ -55,6 +57,14 @@ func (fs *FeedStore) GetUnread() *[]ItemWithFeed {
|
|||||||
return items
|
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 {
|
func (fs *FeedStore) GetAll() *[]ItemWithFeed {
|
||||||
items := &[]ItemWithFeed{}
|
items := &[]ItemWithFeed{}
|
||||||
fs.getDB().Table("items").
|
fs.getDB().Table("items").
|
||||||
|
@ -46,6 +46,7 @@ type Item struct {
|
|||||||
FeedID string
|
FeedID string
|
||||||
Read bool
|
Read bool
|
||||||
Save bool
|
Save bool
|
||||||
|
DeletedAt gorm.DeletedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
type ItemWithFeed struct {
|
type ItemWithFeed struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user