Reimplement upload tracking and purging based on the metadata database

Problem

Upload purging and tracking currently rely on filesystem metadata and as-is consumes a lot of memory and scales poorly.

Context

This issue is to investigate possible solutions for reimplement upload tracking and purging using the metadata database.

Edited by João Pereira