Skip to main content

purge_superseded_versions

Function purge_superseded_versions 

Source
pub async fn purge_superseded_versions(
    pool: &PgPool,
    vault: &Vault,
    grace_days: u32,
    apply: bool,
) -> AppResult<VersionPurge>
Expand description

Removes the old versions of files whose retention is latest: a version goes when a newer version replaced it at least grace_days ago (the time of the next version’s upload counts, so a rollback or a mistaken upload can still be undone within the grace period). The blobs nothing refers to afterwards are removed from the vault. Without apply it only reports.

§Invariants

  • Permission: none – the server’s housekeeping and teamcraft vault purge-versions (an operator with the configuration), no actor (“system”).
  • Locks: per file one transaction with the revision row and the file row (FOR UPDATE), the same order as an upload; the conditions are checked again under the locks.
  • Data: only files with retention = 'latest' whose revision is in work: nothing of an in-review, released or obsolete revision, which is therefore never touched; the current version is never removed; a grace period of 0 days is refused (400).
  • Audit: one file.purge_versions entry per file, in the transaction of the removal, naming the versions and hashes.
  • Atomic: per file; the vault blobs are removed after the commit (checked against every reference and the in-flight grace period).