Periodic job for pruning old content
I fixed my issues with incredibly slow timelines and query timeouts by deleting disabled users, old activities and objects (older than Jan 1 2021), then vacuum full. How about this were a built-in job that runs every X days or something, configurable of course?
It could also be limited to remote only and posts the local users never interacted with, but that makes the query more complicated.
Deleting old stuff also solves the issue of ever growing storage requirements. This almost halved my postgres folder in size.
In my case this deleted about 3 millions of activities and couple hundred thousand objects
This change was needed to delete objects - the constraint prevented anything being deleted:
ALTER TABLE deliveries DROP CONSTRAINT "deliveries_object_id_fkey", ADD CONSTRAINT "deliveries_object_id_fkey" FOREIGN KEY (object_id) REFERENCES objects(id) ON DELETE CASCADE;
Deleting users needed a new index, but I forgot what it was - it shows up when running explain (timing) when deleting a single user.