Running the addbooks command on books already imported results in duplicated cover files
I have about 140 books already imported and each time I run the addbooks command, my static_media grows by 0.9GB. It looks like the cover files get copied even though the book isn't going to be imported.
$ ls static_media/covers
foxgeeseancientn00weiriala_1.gif
foxgeeseancientn00weiriala_2.gif
foxgeeseancientn00weiriala_3.gif
foxgeeseancientn00weiriala_4.gif
foxgeeseancientn00weiriala_5.gif
foxgeeseancientn00weiriala.gif
You can see multiple copies of the same cover file. Each time I run addbooks, a new one is created.
I think this would be fixed if instead of the current "save and check error" strategy, we move to a "check if exists then save" strategy we would avoid the save logic that duplicates the cover file.
Side note, it's okay in some scenarios to create extra files but we would want to include a cleanup job to find orphaned cover files.
Hello, issue is in save() method of Book:
Cover is extracted before calling real save in DB:
by switching logic order, we can insure that cover will be saved only if insertion in DB was OK.
Of course, a cleanup job should be also nice since there is border case (like editing, removing or replacing an ebook).