**Description of the problem:**
Sometime, pages like D25018 (but not limited to Differential diffs) have a bunch of "Unknown Object" in the {nav Referenced Files} section in the "right sidebar".
Example:
{F2236006}
Why?
Probably because they are expired temporarily generated files attached to the diff, but now these files were deleted.
Why?
I assume these references should be deleted since the file "attachment" reference indicates whenever a file is visible to an object (an object may be whatever, like a task).
Why?
The general idea underlying the "attachment" system is that you can have a file with minimal privileges, and a task with specific visibility privileges, and you can attach the file to the task, so that task viewers can also see the file, and you don't have to keep the view privileges in manual sync.
The database schema `phabricator_file.file_attachment` so contains this reference between `<filePHID, objectPHID>`. See the schema:
```
$ mysql phabricator_file
$ SHOW CREATE TABLE file_attachment;
CREATE TABLE `file_attachment` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`objectPHID` varbinary(64) NOT NULL,
`filePHID` varbinary(64) NOT NULL,
`attacherPHID` varbinary(64) DEFAULT NULL,
`attachmentMode` varchar(32) NOT NULL,
`dateCreated` int(10) unsigned NOT NULL,
`dateModified` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `key_object` (`objectPHID`,`filePHID`),
KEY `key_file` (`filePHID`)
)
```
So it's quite self-evident that, if the related file is removed, the entry in the `file_attachment` table should be removed as well.
Also, if the object related to the `objectPHID` is deleted, there is no need to keep this orphan entry in the database.