2023-06-25 14:23:23 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
package cli // import "miniflux.app/v2/internal/cli"
|
2023-06-25 14:23:23 -04:00
|
|
|
|
|
|
|
import (
|
2023-09-24 19:32:09 -04:00
|
|
|
"log/slog"
|
2023-06-25 14:23:23 -04:00
|
|
|
"time"
|
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
"miniflux.app/v2/internal/config"
|
|
|
|
"miniflux.app/v2/internal/metric"
|
|
|
|
"miniflux.app/v2/internal/model"
|
|
|
|
"miniflux.app/v2/internal/storage"
|
2023-06-25 14:23:23 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func runCleanupTasks(store *storage.Storage) {
|
|
|
|
nbSessions := store.CleanOldSessions(config.Opts.CleanupRemoveSessionsDays())
|
|
|
|
nbUserSessions := store.CleanOldUserSessions(config.Opts.CleanupRemoveSessionsDays())
|
2023-09-24 19:32:09 -04:00
|
|
|
slog.Info("Sessions cleanup completed",
|
|
|
|
slog.Int64("application_sessions_removed", nbSessions),
|
|
|
|
slog.Int64("user_sessions_removed", nbUserSessions),
|
|
|
|
)
|
2023-06-25 14:23:23 -04:00
|
|
|
|
|
|
|
startTime := time.Now()
|
|
|
|
if rowsAffected, err := store.ArchiveEntries(model.EntryStatusRead, config.Opts.CleanupArchiveReadDays(), config.Opts.CleanupArchiveBatchSize()); err != nil {
|
2023-09-24 19:32:09 -04:00
|
|
|
slog.Error("Unable to archive read entries", slog.Any("error", err))
|
2023-06-25 14:23:23 -04:00
|
|
|
} else {
|
2023-09-24 19:32:09 -04:00
|
|
|
slog.Info("Archiving read entries completed",
|
|
|
|
slog.Int64("read_entries_archived", rowsAffected),
|
|
|
|
)
|
2023-06-25 14:23:23 -04:00
|
|
|
|
|
|
|
if config.Opts.HasMetricsCollector() {
|
|
|
|
metric.ArchiveEntriesDuration.WithLabelValues(model.EntryStatusRead).Observe(time.Since(startTime).Seconds())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
startTime = time.Now()
|
|
|
|
if rowsAffected, err := store.ArchiveEntries(model.EntryStatusUnread, config.Opts.CleanupArchiveUnreadDays(), config.Opts.CleanupArchiveBatchSize()); err != nil {
|
2023-09-24 19:32:09 -04:00
|
|
|
slog.Error("Unable to archive unread entries", slog.Any("error", err))
|
2023-06-25 14:23:23 -04:00
|
|
|
} else {
|
2023-09-24 19:32:09 -04:00
|
|
|
slog.Info("Archiving unread entries completed",
|
|
|
|
slog.Int64("unread_entries_archived", rowsAffected),
|
|
|
|
)
|
2023-06-25 14:23:23 -04:00
|
|
|
|
|
|
|
if config.Opts.HasMetricsCollector() {
|
|
|
|
metric.ArchiveEntriesDuration.WithLabelValues(model.EntryStatusUnread).Observe(time.Since(startTime).Seconds())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|