When documents are removed and exist on no branches, their cached files are not deleted; they should be.
When documents are removed and exist on no branches, their field data is not removed. It should be.
Fixing subitem 2 will allow us not to have to fix subitem 3. Subitem 3 exists as long as item 2 remains unfixed. The best solution is just to fix item 2.
We need to catch and explicitly disallow the situation where someone deletes a document and then tries to add it back (with the same id). While there are a few instances where this could work (if it exists on no other branches), it is most straightforward just to keep a list of deleted document IDs and not allow them to be re-added. Currently, because the field data is not removed from the table when documents are deleted and exist on no branches, this causes the unusual behavior of the document re-claiming its old field data (which is not updated with any new information). The fix is just not to allow one to add a new document with the same id as any document that has been deleted.
When documents are removed and exist on no branches, their cached files are not deleted; they should be.
When documents are removed and exist on no branches, their field data is not removed. It should be.
Fixing subitem 2 will allow us not to have to fix subitem 3. Subitem 3 exists as long as item 2 remains unfixed. The best solution is just to fix item 2.