data_retention.go
TLDR
This file contains the implementation of the RunDataRetention
method for the BoardsApp
struct in the boards
package. It also includes the convertDaysToCutoff
function.
Methods
RunDataRetention
This method is part of the BoardsApp
struct and is responsible for running the data retention process. It checks if the appropriate license is available and the data retention feature is enabled in the server configuration. If both conditions are met, it calculates the end time of retention based on the configured number of days and calls the RunDataRetention
method of the server store with the calculated end time and a batch size. It returns the number of records affected by the data retention process or an error if the appropriate license is not available.
Functions
convertDaysToCutoff
This function takes a number of days and a time value and calculates the cutoff date by subtracting the specified number of days from the given time value. It returns the cutoff date in milliseconds since Unix epoch.
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package boards
import (
"errors"
"time"
)
var ErrInsufficientLicense = errors.New("appropriate license required")
func (b *BoardsApp) RunDataRetention(nowTime, batchSize int64) (int64, error) {
b.logger.Debug("Boards RunDataRetention")
license := b.server.Store().GetLicense()
if license == nil || !(*license.Features.DataRetention) {
return 0, ErrInsufficientLicense
}
if b.server.Config().EnableDataRetention {
boardsRetentionDays := b.server.Config().DataRetentionDays
endTimeBoards := convertDaysToCutoff(boardsRetentionDays, time.Unix(nowTime/1000, 0))
return b.server.Store().RunDataRetention(endTimeBoards, batchSize)
}
return 0, nil
}
func convertDaysToCutoff(days int, now time.Time) int64 {
upToStartOfDay := now.AddDate(0, 0, -days)
cutoffDate := time.Date(upToStartOfDay.Year(), upToStartOfDay.Month(), upToStartOfDay.Day(), 0, 0, 0, 0, time.Local)
return cutoffDate.UnixNano() / int64(time.Millisecond)
}