Atsumeru-xyz / Atsumeru

Free self-hosted mangas/comics/light novels media server
https://atsumeru.xyz
MIT License
86 stars 5 forks source link

Bug in history in the number of pages of a volume #2

Open Metaroka opened 1 year ago

Metaroka commented 1 year ago

The history does not update the total number of pages in the volume if they are added or deleted.

This corrects the situation:

UPDATE HISTORY SET PAGES_COUNT = NULL;

UPDATE HISTORY
SET PAGES_COUNT = 
  CASE 
    WHEN PAGES_COUNT IS NULL AND ARCHIVE_HASH IN (SELECT MANGA_ID FROM BOOK_ARCHIVES) 
      THEN (SELECT PAGES_COUNT FROM BOOK_ARCHIVES WHERE BOOK_ARCHIVES.MANGA_ID = HISTORY.ARCHIVE_HASH)
    WHEN PAGES_COUNT IS NULL AND CHAPTER_HASH IN (SELECT CHAPTER_ID FROM BOOK_CHAPTERS) 
      THEN (SELECT PAGES_COUNT FROM BOOK_CHAPTERS WHERE BOOK_CHAPTERS.CHAPTER_ID = HISTORY.CHAPTER_HASH)
    ELSE PAGES_COUNT 
  END;