1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-11-25 15:42:01 +02:00

fixed logs delete check

This commit is contained in:
Gani Georgiev
2024-07-09 18:30:23 +03:00
parent f9fcea8770
commit 1e8e70c53c
2 changed files with 46 additions and 14 deletions

View File

@@ -1256,13 +1256,15 @@ func (app *BaseApp) initLogger() error {
return nil
})
// delete old logs
// @todo replace with cron so that it doesn't rely on the logs write
//
// delete old logs (~ once 1 day)
// ---
logsMaxDays := app.Settings().Logs.MaxDays
now := time.Now()
lastLogsDeletedAt := cast.ToTime(app.Store().Get("lastLogsDeletedAt"))
daysDiff := now.Sub(lastLogsDeletedAt).Hours() / 24
if daysDiff >= float64(logsMaxDays) {
if daysDiff >= 1 {
deleteErr := app.LogsDao().DeleteOldLogs(now.AddDate(0, 0, -1*logsMaxDays))
if deleteErr == nil {
app.Store().Set("lastLogsDeletedAt", now)