Manual cherry-pick of (37969b1) #34155 into release 10.11. (#34334)

Automatic Merge
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2025-10-30 16:29:11 +01:00
коммит произвёл GitHub
родитель b922174f48
Коммит 75132b7a91
3 изменённых файлов: 84 добавлений и 30 удалений

Просмотреть файл

@@ -418,9 +418,24 @@ func (ds *DatabaseStore) Close() error {
return ds.db.Close()
}
// removes configurations from database if they are older than threshold.
func (ds *DatabaseStore) cleanUp(thresholdCreatAt int) error {
if _, err := ds.db.NamedExec("DELETE FROM Configurations Where CreateAt < :timestamp", map[string]any{"timestamp": thresholdCreatAt}); err != nil {
// removes configurations from database if they are older than threshold,
// keeping the active configuration and the last 5 most recent ones.
func (ds *DatabaseStore) cleanUp(thresholdCreateAt int64) error {
query := `
DELETE FROM Configurations
WHERE CreateAt < :timestamp
AND (Active IS NULL OR Active = false)
AND ID NOT IN (
SELECT ID FROM (
SELECT ID
FROM Configurations
ORDER BY CreateAt DESC
LIMIT 5
) AS recent
);
`
if _, err := ds.db.NamedExec(query, map[string]any{"timestamp": thresholdCreateAt}); err != nil {
return errors.Wrap(err, "unable to clean Configurations table")
}