@ -7,7 +7,6 @@ import (
"github.com/grafana/grafana/pkg/apimachinery/identity"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/services/dashboardsnapshots"
"github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/setting"
@ -15,10 +14,6 @@ import (
type DashboardSnapshotStore struct {
store db . DB
log log . Logger
// deprecated behavior
skipDeleteExpired bool
}
// DashboardStore implements the Store interface
@ -26,25 +21,17 @@ var _ dashboardsnapshots.Store = (*DashboardSnapshotStore)(nil)
func ProvideStore ( db db . DB , cfg * setting . Cfg ) * DashboardSnapshotStore {
// nolint:staticcheck
return NewStore ( db , ! cfg . SnapShotRemoveExpired )
return NewStore ( db )
}
func NewStore ( db db . DB , skipDeleteExpired bool ) * DashboardSnapshotStore {
log := log . New ( "dashboardsnapshot.store" )
if skipDeleteExpired {
log . Warn ( "[Deprecated] The snapshot_remove_expired setting is outdated. Please remove from your config." )
}
return & DashboardSnapshotStore { store : db , skipDeleteExpired : skipDeleteExpired }
func NewStore ( db db . DB ) * DashboardSnapshotStore {
return & DashboardSnapshotStore { store : db }
}
// DeleteExpiredSnapshots removes snapshots with old expiry dates.
// SnapShotRemoveExpired is deprecated and should be removed in the future.
// Snapshot expiry is decided by the user when they share the snapshot.
func ( d * DashboardSnapshotStore ) DeleteExpiredSnapshots ( ctx context . Context , cmd * dashboardsnapshots . DeleteExpiredSnapshotsCommand ) error {
if d . skipDeleteExpired {
d . log . Warn ( "[Deprecated] The snapshot_remove_expired setting is outdated. Please remove from your config." )
return nil
}
return d . store . WithDbSession ( ctx , func ( sess * db . Session ) error {
deleteExpiredSQL := "DELETE FROM dashboard_snapshot WHERE expires < ?"
expiredResponse , err := sess . Exec ( deleteExpiredSQL , time . Now ( ) )