Add worker to cleanup orphaned packages_nuget_symbols records
The following discussion from !129916 (merged) should be addressed:
-
@10io started a discussion: (+1 comment) We can't have
on_delete: :cascade.The problem is that this table holds a reference to a file located on object storage. If we let the database delete these rows when a
packages_packagesrow is removed, then the file on object storage is left behind.We have two ways to solve this:
- Let rails handle the cascade of deletes with
has_many .... dependent: :destroy. - In NPM metadata caches, we are trying a new approach:
-
nullifythe foreign key when the parent object is deleted. See this part. - Have a background worker cleanup that will detect those stale rows and delete them one by one using standard rails methods (like
destroy!) which in turn will properly remove files from object storage. - For this to work, we need to entire object storage key within the considered record.
-
From what I see here, you're going for (2.). If that's the case, we will need to update this
on_deletestatement and have a follow up issue for the background cleaner worker. Regarding the worker, there might be a way that it supports multiple tables. A bit like the uploader class, I'm convinced that we can centralize things for models that have theobject_storage_keycolumn. - Let rails handle the cascade of deletes with