mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
Fixes #31432 - Added campaign target cleanup: Deletes targets from campaigns completed >24h ago. Uses 10% or 50k min per run, processes in 10k batches. Added DB index, integrated into hourly cron, includes tests. # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. ## Testing - [x] Added/updated automated tests - [x] Where appropriate, [automated tests simulate multiple hosts and test for host isolation](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/reference/patterns-backend.md#unit-testing) (updates to one hosts's records do not affect another) - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Automatic cleanup of live query campaign targets 24 hours after campaign completion to reduce clutter and storage usage. - Chores - Added a database index to speed up live query target operations for improved performance at scale. - Enhanced scheduled maintenance to log cleanup counts and execution time for better observability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
23 lines
570 B
Go
23 lines
570 B
Go
package tables
|
|
|
|
import (
|
|
"database/sql"
|
|
)
|
|
|
|
func init() {
|
|
MigrationClient.AddMigration(Up_20250827113140, Down_20250827113140)
|
|
}
|
|
|
|
func Up_20250827113140(tx *sql.Tx) error {
|
|
// Add index on distributed_query_campaign_id column to improve query performance
|
|
// This is the most common WHERE clause used when querying this table
|
|
_, err := tx.Exec(`
|
|
ALTER TABLE distributed_query_campaign_targets
|
|
ADD INDEX idx_distributed_query_campaign_targets_campaign_id (distributed_query_campaign_id)
|
|
`)
|
|
return err
|
|
}
|
|
|
|
func Down_20250827113140(_ *sql.Tx) error {
|
|
return nil
|
|
}
|