WoltLab / com.woltlab.wcf.conversation

User Conversation System
GNU Lesser General Public License v2.1
13 stars 13 forks source link

Clean up orphaned attachments #158

Closed TimWolla closed 2 years ago

TimWolla commented 3 years ago

It appears that cleanup might just be missing in cases of error / bugs. Checking WoltLab.com this appears to affect a low 2-digit number of attachments. I would be fine with delaying this until the next larger upgrade nonetheless. It's no severe reliability issue and it might also affect the other apps.

SELECT *
FROM `wcf1_attachment`
WHERE objecttypeid IN
    (SELECT objecttypeid
     FROM wcf1_object_type
     WHERE objecttype = 'com.woltlab.wcf.conversation.message'
       AND definitionid IN
         (SELECT definitionid
          FROM wcf1_object_type_definition
          WHERE definitionname = 'com.woltlab.wcf.attachment.objectType' ))
  AND objectid NOT IN
    (SELECT messageid
     FROM wcf1_conversation_message); 

Originally posted by @TimWolla in https://github.com/WoltLab/com.woltlab.wcf.conversation/issues/157#issuecomment-925731970