Skip to content

Batch the reporting-data purge so it survives large tables#197

Open
kennygutierrez wants to merge 1 commit into
andrewmarkham:release/v3.2.0from
kennygutierrez:feature/batched-purge-reporting-data
Open

Batch the reporting-data purge so it survives large tables#197
kennygutierrez wants to merge 1 commit into
andrewmarkham:release/v3.2.0from
kennygutierrez:feature/batched-purge-reporting-data

Conversation

@kennygutierrez
Copy link
Copy Markdown

On sites that have been collecting CSP reports for a while, SecurityReportTo can hold millions of rows. The purge job's single unbounded DELETE exceeds the SqlCommand timeout and rolls back, so the table never shrinks.

Changes:

  • Add ReportingOptions.PurgeBatchSize (default 5000; <= 0 restores the original single-DELETE behavior).
  • IReportingRepository.PurgeReporingData gains an optional int? batchSize. Source-compatible with existing callers.
  • SQL provider switches to DELETE TOP (@batchsize) when a batch size is supplied; ElasticSearch ignores it since DeleteByQuery already handles bulk deletes.
  • PurgeReporintgDataJob loops batch-by-batch, reports progress via OnStatusChanged, and is now IsStoppable.

On sites that have been collecting CSP reports for a while,
SecurityReportTo can hold millions of rows. The purge job's
single unbounded DELETE exceeds the SqlCommand timeout and
rolls back, so the table never shrinks.

Changes:
- Add ReportingOptions.PurgeBatchSize (default 5000; <= 0
  restores the original single-DELETE behavior).
- IReportingRepository.PurgeReporingData gains an optional
  int? batchSize. Source-compatible with existing callers.
- SQL provider switches to DELETE TOP (@batchsize) when a
  batch size is supplied; ElasticSearch ignores it since
  DeleteByQuery already handles bulk deletes.
- PurgeReporintgDataJob loops batch-by-batch, reports
  progress via OnStatusChanged, and is now IsStoppable.
@andrewmarkham
Copy link
Copy Markdown
Owner

Hi @kennygutierrez

Thanks for creating this, I really appreciate it. Can I ask that you change the target branch to release/v3.2.0.

I can then update the version numbers and documentation.

@kennygutierrez kennygutierrez changed the base branch from main to release/v3.2.0 May 21, 2026 14:17
@kennygutierrez
Copy link
Copy Markdown
Author

Andrew, I changed the target. Hope I did it right!

@andrewmarkham
Copy link
Copy Markdown
Owner

@kennygutierrez I will take a look at getting this merged and released. It may take a few days as I am just about to go on holiday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants