Deleting images on JungleDragon
January 17, 2010
Earlier this year I demonstrated how I dramatically improved the upload experience in JungleDragon. That story reveals that there is quite a lot going on when you upload an image. Today, I experienced that the opposite was true as well: deleting an image from JungleDragon is complex.
Complex is perhaps an overstatement, but there’s quite some things to deal with:
- There are a lot of relations in the database to an image record, for example comments, votes, revisions, favorites and tags. Therefore, I had to implement cascading deletes on the foreign keys to really clean up everything related to that image.
- Tag records have to dealt with seperately. I can delete the mapping between the tag and the image, but not the tags of the images to be deleted, because there may be other images associated with it.
- The karma log, or activity stream as I demonstrated earlier, is like a historic record of activity. I cannot just delete historic entries because the image is deleted, that would make the overview inconsistent. Therefore, I had to cache some image data in the karma log, and for deleted images not show the preview of the image anymore (because it is deleted), instead I’m showing a “deleted” icon.
- Any karma that the user has earned via the image to be deleted has to be taken away. I had to make a roundtrip through all code to see if I implemented this correctly, because a karma “leak” would be a disaster to the reputation system.
- The actual image files have to be deleted, depending on where they are stored (local, Amazon S3, or both). I also implemented a DELETE_MODE setting in the back-end. When set to “hard” it will delete image files, when set to “soft” it will delete the database records, but not the image files.
- All of the above has to work like a transaction: any failure should mean a complete rollback, and only a commit is made when every atomic part is successful.
This is just a really long way of saying: deleting an image is done, was hard, but I’m happy it is behind me now. There is little to demonstrate about deleting an image, but this partial screenshot shows what happens in the karma log of a user when the image in question is deleted:
I could have gone for more sophistication in soft delete mode, for example by always saving at least the thumbnail of a deleted image, but for now I long for simplicity, it is complex enough as it is.
