Determine if an upload is referenced by an issue or merge request.

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

To implement Manage Discussion Storage and/or Attachment Manager, we need to determine if an upload is being referenced by an issue.

Problem

There is no direct way to track images that are not being referenced on issues or merge request. Consider the following example:

  1. User creates a new issue
  2. User attach file picture_1.png on the issue description
    • GitLab process picture_1.png and stores it.
  3. User realizes it was the wrong file and removes the markdown tags from the issue description
  4. User uploads file picture_2.png
    • Gitlab process picture_2.png and stores it.
  5. User saves the issue.

GitLab ends up with two pictures, one of them not being used anywhere.

Proposal

Have a column that stores if an upload is being referenced or not

upload = project.uploads.last
upload.referenced?
=> true # upload appears on an issue or a merge request

Technical details (wip)

  1. Add a column on uploads
  2. Add a background migration to populate uploads
  3. Add an async job that verifies if an upload is referenced by an issue or a merge request.

Downsides

  1. Records to be updated by the background migration will be quite large.
Edited by 🤖 GitLab Bot 🤖