mirror of
https://github.com/miniflux/v2.git
synced 2025-08-26 18:21:01 +00:00
refactor(cli): use time.Duration for cleanup tasks
This commit is contained in:
parent
7060ecc163
commit
983291c78b
8 changed files with 94 additions and 45 deletions
|
@ -392,9 +392,9 @@ func (s *Storage) RefreshFeedEntries(userID, feedID int64, entries model.Entries
|
|||
return newEntries, nil
|
||||
}
|
||||
|
||||
// ArchiveEntries changes the status of entries to "removed" after the given number of days.
|
||||
func (s *Storage) ArchiveEntries(status string, days, limit int) (int64, error) {
|
||||
if days < 0 || limit <= 0 {
|
||||
// ArchiveEntries changes the status of entries to "removed" after the interval (24h minimum).
|
||||
func (s *Storage) ArchiveEntries(status string, interval time.Duration, limit int) (int64, error) {
|
||||
if interval < 0 || limit <= 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
|
@ -419,6 +419,8 @@ func (s *Storage) ArchiveEntries(status string, days, limit int) (int64, error)
|
|||
)
|
||||
`
|
||||
|
||||
days := max(int(interval/(24*time.Hour)), 1)
|
||||
|
||||
result, err := s.db.Exec(query, model.EntryStatusRemoved, status, fmt.Sprintf("%d days", days), limit)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf(`store: unable to archive %s entries: %v`, status, err)
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"crypto/rand"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"miniflux.app/v2/internal/model"
|
||||
)
|
||||
|
@ -122,14 +123,17 @@ func (s *Storage) FlushAllSessions() (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
// CleanOldSessions removes sessions older than specified days.
|
||||
func (s *Storage) CleanOldSessions(days int) int64 {
|
||||
// CleanOldSessions removes sessions older than specified interval (24h minimum).
|
||||
func (s *Storage) CleanOldSessions(interval time.Duration) int64 {
|
||||
query := `
|
||||
DELETE FROM
|
||||
sessions
|
||||
WHERE
|
||||
created_at < now() - $1::interval
|
||||
`
|
||||
|
||||
days := max(int(interval/(24*time.Hour)), 1)
|
||||
|
||||
result, err := s.db.Exec(query, fmt.Sprintf("%d days", days))
|
||||
if err != nil {
|
||||
return 0
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"crypto/rand"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"miniflux.app/v2/internal/model"
|
||||
)
|
||||
|
@ -43,7 +44,6 @@ func (s *Storage) UserSessions(userID int64) (model.UserSessions, error) {
|
|||
&session.UserAgent,
|
||||
&session.IP,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(`store: unable to fetch user session row: %v`, err)
|
||||
}
|
||||
|
@ -164,14 +164,17 @@ func (s *Storage) RemoveUserSessionByID(userID, sessionID int64) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// CleanOldUserSessions removes user sessions older than specified days.
|
||||
func (s *Storage) CleanOldUserSessions(days int) int64 {
|
||||
// CleanOldUserSessions removes user sessions older than specified interval (24h minimum).
|
||||
func (s *Storage) CleanOldUserSessions(interval time.Duration) int64 {
|
||||
query := `
|
||||
DELETE FROM
|
||||
user_sessions
|
||||
WHERE
|
||||
created_at < now() - $1::interval
|
||||
`
|
||||
|
||||
days := max(int(interval/(24*time.Hour)), 1)
|
||||
|
||||
result, err := s.db.Exec(query, fmt.Sprintf("%d days", days))
|
||||
if err != nil {
|
||||
return 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue