Update Maven snapshot cleanup slices directly instead of through each_batch
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Problem
The Maven snapshot pass in Packages::Cleanup::ExecutePolicyService (!266409 (merged)) marks old snapshot files through each_batch over a relation that only ever holds one batch. Each 200-id slice pays a start query and a boundary query before the UPDATE.
Proposal
Update each slice directly, like mark_packages_for_destruction does:
old_ids_by_name.values.flatten.each_slice(MARK_PACKAGE_FILES_FOR_DESTRUCTION_SERVICE_BATCH_SIZE) do |ids|
break :timeout if batch_deadline.past?
@counts[:marked_package_files_total_count] +=
::Packages::PackageFile.id_in(ids).update_all(status: :pending_destruction)
endThat's one statement per slice. The snapshot when a timeout is hit spec then stubs batch_deadline instead of the service.
Suggested by @daniyalAD in !266409 (merged) (discussion 2ebf0761).
Edited by 🤖 GitLab Bot 🤖