1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-06 17:41:00 +00:00

Add scheduler to clean old sessions

This commit is contained in:
Frédéric Guillot 2017-12-16 18:48:17 -08:00
parent 00257988ef
commit 18f55d1569
5 changed files with 60 additions and 17 deletions

View file

@ -127,3 +127,17 @@ func (s *Storage) RemoveUserSessionByID(userID, sessionID int64) error {
return nil
}
// CleanOldUserSessions removes user sessions older than 30 days.
func (s *Storage) CleanOldUserSessions() int64 {
query := `DELETE FROM user_sessions
WHERE id IN (SELECT id FROM user_sessions WHERE created_at < now() - interval '30 days')`
result, err := s.db.Exec(query)
if err != nil {
return 0
}
n, _ := result.RowsAffected()
return n
}