import kotlin.Int; CREATE VIEW updatesView AS SELECT manga.id AS mangaId, manga.remote_title AS mangaTitle, chapter.id AS chapterId, chapter.remote_name AS chapterName, chapter.remote_scanlator AS scanlator, chapter.remote_url AS chapterUrl, chapter.user_read AS read, chapter.user_bookmark AS bookmark, chapter.user_last_page_read AS lastPageRead, manga.source_id AS sourceId, manga.user_favorite_at IS NOT NULL AS favorite, manga.remote_cover AS thumbnailUrl, manga.state_cover_last_modified AS coverLastModified, chapter.remote_date_upload AS dateUpload, chapter.state_date_fetch AS dateFetch, excluded_scanlator.scanlator AS excludedScanlator FROM manga JOIN chapter ON manga.id = chapter.manga_id LEFT JOIN excluded_scanlator ON manga.id = excluded_scanlator.manga_id AND chapter.remote_scanlator = excluded_scanlator.scanlator WHERE user_favorite_at IS NOT NULL AND state_date_fetch > user_favorite_at ORDER BY state_date_fetch DESC; getRecentUpdatesWithFilters: SELECT mangaId, mangaTitle, chapterId, chapterName, scanlator, chapterUrl, read, bookmark, lastPageRead, sourceId, favorite, thumbnailUrl, coverLastModified, dateUpload, dateFetch, excludedScanlator FROM updatesView WHERE dateUpload > :after AND (:read IS NULL OR read = :read) -- Started means some progress but not finished, Read means finished chapter, thus: AND ( :started IS NULL OR (:started = 1 AND lastPageRead > 0 AND read = 0) OR (:started = 0 AND lastPageRead = 0 AND read = 0) ) AND (:bookmarked IS NULL OR bookmark = :bookmarked) AND (excludedScanlator IS NULL OR :hideExcludedScanlators = 0) AND ( -- includedEmpty being true expresses "don't care" state and bypasses the membership filter :includedEmpty OR EXISTS ( SELECT 1 FROM manga_category WHERE manga_category.manga_id = mangaId AND manga_category.category_id IN :includedCategories ) OR (0 IN :includedCategories AND NOT EXISTS ( SELECT 1 FROM manga_category WHERE manga_category.manga_id = mangaId) ) ) AND ( -- excludedEmpty being true expresses "don't care" state and bypasses the membership filter :excludedEmpty OR ( NOT EXISTS ( SELECT 1 FROM manga_category WHERE manga_category.manga_id = mangaId AND manga_category.category_id IN :excludedCategories ) AND ( 0 NOT IN :excludedCategories OR EXISTS (SELECT 1 FROM manga_category WHERE manga_category.manga_id = mangaId) ) ) ) ORDER BY dateFetch DESC LIMIT :limit; getReadUpdates: SELECT mangaId, mangaTitle, chapterId, chapterName, scanlator, chapterUrl, read, bookmark, lastPageRead, sourceId, favorite, thumbnailUrl, coverLastModified, dateUpload, dateFetch, excludedScanlator FROM updatesView WHERE read = 1 AND dateUpload > :after ORDER BY dateFetch DESC LIMIT :limit; getUnreadUpdates: SELECT mangaId, mangaTitle, chapterId, chapterName, scanlator, chapterUrl, read, bookmark, lastPageRead, sourceId, favorite, thumbnailUrl, coverLastModified, dateUpload, dateFetch, excludedScanlator FROM updatesView WHERE read = 0 AND dateUpload > :after ORDER BY dateFetch DESC LIMIT :limit;