mirror of
https://github.com/miniflux/v2.git
synced 2025-06-27 16:36:00 +00:00
Archive read entries automatically after 60 days
This commit is contained in:
parent
ff8e0c6b3d
commit
f19ab21b7d
4 changed files with 36 additions and 19 deletions
|
@ -13,18 +13,18 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultBaseURL = "http://localhost"
|
defaultBaseURL = "http://localhost"
|
||||||
defaultDatabaseURL = "postgres://postgres:postgres@localhost/miniflux2?sslmode=disable"
|
defaultDatabaseURL = "postgres://postgres:postgres@localhost/miniflux2?sslmode=disable"
|
||||||
defaultWorkerPoolSize = 5
|
defaultWorkerPoolSize = 5
|
||||||
defaultPollingFrequency = 60
|
defaultPollingFrequency = 60
|
||||||
defaultBatchSize = 10
|
defaultBatchSize = 10
|
||||||
defaultDatabaseMaxConns = 20
|
defaultDatabaseMaxConns = 20
|
||||||
defaultListenAddr = "127.0.0.1:8080"
|
defaultListenAddr = "127.0.0.1:8080"
|
||||||
defaultCertFile = ""
|
defaultCertFile = ""
|
||||||
defaultKeyFile = ""
|
defaultKeyFile = ""
|
||||||
defaultCertDomain = ""
|
defaultCertDomain = ""
|
||||||
defaultCertCache = "/tmp/cert_cache"
|
defaultCertCache = "/tmp/cert_cache"
|
||||||
defaultSessionCleanupFrequency = 24
|
defaultCleanupFrequency = 24
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config manages configuration parameters.
|
// Config manages configuration parameters.
|
||||||
|
@ -137,9 +137,9 @@ func (c *Config) CertCache() string {
|
||||||
return c.get("CERT_CACHE", defaultCertCache)
|
return c.get("CERT_CACHE", defaultCertCache)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SessionCleanupFrequency returns the interval for session cleanup.
|
// CleanupFrequency returns the interval for cleanup jobs.
|
||||||
func (c *Config) SessionCleanupFrequency() int {
|
func (c *Config) CleanupFrequency() int {
|
||||||
return c.getInt("SESSION_CLEANUP_FREQUENCY", defaultSessionCleanupFrequency)
|
return c.getInt("CLEANUP_FREQUENCY", defaultCleanupFrequency)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WorkerPoolSize returns the number of background worker.
|
// WorkerPoolSize returns the number of background worker.
|
||||||
|
|
|
@ -50,7 +50,7 @@ func Run(cfg *config.Config, store *storage.Storage) {
|
||||||
cfg.BatchSize(),
|
cfg.BatchSize(),
|
||||||
)
|
)
|
||||||
|
|
||||||
scheduler.NewSessionScheduler(store, cfg.SessionCleanupFrequency())
|
scheduler.NewCleanupScheduler(store, cfg.CleanupFrequency())
|
||||||
|
|
||||||
<-stop
|
<-stop
|
||||||
logger.Info("Shutting down the server...")
|
logger.Info("Shutting down the server...")
|
||||||
|
|
|
@ -27,14 +27,18 @@ func NewFeedScheduler(store *storage.Storage, workerPool *WorkerPool, frequency,
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSessionScheduler starts a new scheduler that clean old sessions.
|
// NewCleanupScheduler starts a new scheduler that clean old sessions and archive read items.
|
||||||
func NewSessionScheduler(store *storage.Storage, frequency int) {
|
func NewCleanupScheduler(store *storage.Storage, frequency int) {
|
||||||
go func() {
|
go func() {
|
||||||
c := time.Tick(time.Duration(frequency) * time.Hour)
|
c := time.Tick(time.Duration(frequency) * time.Hour)
|
||||||
for range c {
|
for range c {
|
||||||
nbSessions := store.CleanOldSessions()
|
nbSessions := store.CleanOldSessions()
|
||||||
nbUserSessions := store.CleanOldUserSessions()
|
nbUserSessions := store.CleanOldUserSessions()
|
||||||
logger.Info("[SessionScheduler] cleaned %d sessions and %d user sessions", nbSessions, nbUserSessions)
|
logger.Info("[CleanupScheduler] Cleaned %d sessions and %d user sessions", nbSessions, nbUserSessions)
|
||||||
|
|
||||||
|
if err := store.ArchiveEntries(); err != nil {
|
||||||
|
logger.Error("[CleanupScheduler] %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,6 +176,19 @@ func (s *Storage) cleanupEntries(feedID int64, entryHashes []string) error {
|
||||||
return nil
|
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.
|
// SetEntriesStatus update the status of the given list of entries.
|
||||||
func (s *Storage) SetEntriesStatus(userID int64, entryIDs []int64, status string) error {
|
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))
|
defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:SetEntriesStatus] userID=%d, entryIDs=%v, status=%s", userID, entryIDs, status))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue