refactor(recents): Some adjustments

This commit is contained in:
Ahmad Ansori Palembani 2024-12-09 20:20:12 +07:00
parent 07ed81454f
commit 22978ab8bf
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
4 changed files with 80 additions and 78 deletions

View file

@ -69,7 +69,7 @@ ON C._id = H.history_chapter_id
AND H.history_last_read > 0
LEFT JOIN scanlators_view AS S
ON C.manga_id = S.manga_id
AND ifnull(C.scanlator, 'N/A') = ifnull(S.name, '/<INVALID>/') -- I assume if it's N/A it shouldn't be filtered
AND C.scanlator = S.name
WHERE lower(M.title) LIKE '%' || :search || '%'
AND (
:apply_filter = 0 OR S.name IS NULL
@ -101,7 +101,7 @@ AND max_last_read.history_chapter_id = H.history_chapter_id
AND max_last_read.history_last_read > 0
LEFT JOIN scanlators_view AS S
ON C.manga_id = S.manga_id
AND ifnull(C.scanlator, 'N/A') = ifnull(S.name, '/<INVALID>/') -- I assume if it's N/A it shouldn't be filtered
AND C.scanlator = S.name
WHERE lower(M.title) LIKE '%' || :search || '%'
AND (
:apply_filter = 0 OR S.name IS NULL
@ -110,10 +110,10 @@ ORDER BY max_last_read.history_last_read DESC
LIMIT :limit OFFSET :offset;
getRecentsAll:
SELECT R.* FROM (
SELECT R1.* FROM (
SELECT
M.*,
chapters.*,
C.*,
history.history_id AS history_id,
history.history_chapter_id AS history_chapter_id,
history.history_last_read AS history_last_read,
@ -122,71 +122,71 @@ FROM (
SELECT M2.*
FROM mangas AS M2
LEFT JOIN (
SELECT manga_id, COUNT(*) AS unread
SELECT manga_id, COUNT(*) AS value
FROM chapters
WHERE read = 0
GROUP BY manga_id
) AS C
ON M2._id = C.manga_id
) AS unread
ON M2._id = unread.manga_id
WHERE (
:include_read = 0 OR C.unread > 0
:include_read = 0 OR unread.value > 0
)
GROUP BY M2._id
ORDER BY title
) AS M
JOIN chapters
ON M._id = chapters.manga_id
JOIN chapters AS C
ON M._id = C.manga_id
JOIN history
ON chapters._id = history.history_chapter_id
ON C._id = history.history_chapter_id
JOIN (
SELECT
chapters.manga_id AS manga_id,
chapters._id AS history_chapter_id,
MAX(history.history_last_read) AS history_last_read
FROM chapters JOIN history
ON chapters._id = history.history_chapter_id
GROUP BY chapters.manga_id
C2.manga_id AS manga_id,
C2._id AS history_chapter_id,
MAX(H2.history_last_read) AS history_last_read
FROM chapters AS C2 JOIN history AS H2
ON C2._id = H2.history_chapter_id
GROUP BY C2.manga_id
) AS max_last_read
ON chapters.manga_id = max_last_read.manga_id
ON C.manga_id = max_last_read.manga_id
AND max_last_read.history_chapter_id = history.history_chapter_id
AND max_last_read.history_last_read > 0
LEFT JOIN scanlators_view AS S
ON chapters.manga_id = S.manga_id
AND ifnull(chapters.scanlator, 'N/A') = ifnull(S.name, '/<INVALID>/') -- I assume if it's N/A it shouldn't be filtered
ON C.manga_id = S.manga_id
AND C.scanlator = S.name
WHERE lower(title) LIKE '%' || :search || '%'
AND (
:apply_filter = 0 OR S.name IS NULL
)
) AS R
) AS R1
UNION --
UNION -- Newly added chapter
SELECT R.* FROM (
SELECT R2.* FROM (
SELECT
M.*,
chapters.*,
C.*,
NULL AS history_id,
NULL AS history_chapter_id,
chapters.date_fetch AS history_last_read,
C.date_fetch AS history_last_read,
NULL AS history_time_read
FROM mangas AS M
JOIN chapters
ON M._id = chapters.manga_id
JOIN chapters AS C
ON M._id = C.manga_id
JOIN history
ON chapters._id = history.history_chapter_id
ON C._id = history.history_chapter_id
JOIN (
SELECT
manga_id,
chapters._id AS history_chapter_id,
C2.manga_id,
C2._id AS history_chapter_id,
max(date_upload)
FROM chapters JOIN mangas AS M2
ON M2._id = manga_id
WHERE read = 0
GROUP BY manga_id
FROM chapters AS C2 JOIN mangas AS M2
ON M2._id = C2.manga_id
WHERE C2.read = 0
GROUP BY C2.manga_id
) AS newest_chapter
LEFT JOIN scanlators_view AS S
ON chapters.manga_id = S.manga_id
AND ifnull(chapters.scanlator, 'N/A') = ifnull(S.name, '/<INVALID>/') -- I assume if it's N/A it shouldn't be filtered
ON C.manga_id = S.manga_id
AND C.scanlator = S.name
WHERE favorite = 1
AND newest_chapter.history_chapter_id = history.history_chapter_id
AND date_fetch > date_added
@ -194,14 +194,14 @@ AND lower(title) LIKE '%' || :search || '%'
AND (
:apply_filter = 0 OR S.name IS NULL
)
) AS R
) AS R2
UNION --
UNION -- Newly added manga
SELECT R.* FROM (
SELECT R3.* FROM (
SELECT
M.*,
chapters.*,
C.*,
NULL AS history_id,
NULL AS history_chapter_id,
M.date_added AS history_last_read,
@ -222,9 +222,9 @@ JOIN (
NULL AS pages_left,
NULL AS chapter_number,
NULL AS source_order
) AS chapters
) AS C
WHERE favorite = 1
AND lower(title) LIKE '%' || :search || '%'
) AS R
) AS R3
ORDER BY history_last_read DESC
LIMIT :limit OFFSET :offset;