Skip to content

Commit 30d7b38

Browse files
committed
fix: Fix Komga unread count (again)
1 parent 723abbe commit 30d7b38

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
DROP VIEW IF EXISTS scanlators_view;
2+
CREATE VIEW scanlators_view AS
3+
SELECT S.* FROM (
4+
WITH RECURSIVE split(seq, _id, name, str) AS (
5+
SELECT 0, mangas._id, NULL, mangas.filtered_scanlators||' [.] ' FROM mangas WHERE mangas._id
6+
UNION ALL SELECT
7+
seq+1,
8+
_id,
9+
substr(str, 0, instr(str, ' [.] ')),
10+
substr(str, instr(str, ' [.] ')+5)
11+
FROM split WHERE str != ''
12+
)
13+
SELECT _id AS manga_id, name FROM split WHERE name != '' ORDER BY split.seq ASC
14+
) AS S;
15+
16+
DROP VIEW IF EXISTS library_view;
17+
CREATE VIEW library_view AS
18+
SELECT
19+
M.*,
20+
coalesce(C.total, 0) AS total,
21+
coalesce(C.read_count, 0) AS has_read,
22+
coalesce(C.bookmark_count, 0) AS bookmark_count,
23+
coalesce(MC.category_id, 0) AS category,
24+
coalesce(C.latestUpload, 0) AS latestUpload,
25+
coalesce(C.lastRead, 0) AS lastRead,
26+
coalesce(C.lastFetch, 0) AS lastFetch
27+
FROM mangas AS M
28+
LEFT JOIN (
29+
SELECT
30+
chapters.manga_id,
31+
count(*) AS total,
32+
sum(read) AS read_count,
33+
sum(bookmark) AS bookmark_count,
34+
coalesce(max(chapters.date_upload), 0) AS latestUpload,
35+
coalesce(max(history.history_last_read), 0) AS lastRead,
36+
coalesce(max(chapters.date_fetch), 0) AS lastFetch
37+
FROM chapters
38+
LEFT JOIN scanlators_view AS filtered_scanlators
39+
ON chapters.manga_id = filtered_scanlators.manga_id
40+
AND chapters.scanlator = filtered_scanlators.name
41+
LEFT JOIN history
42+
ON chapters._id = history.history_chapter_id
43+
WHERE filtered_scanlators.name IS NULL
44+
GROUP BY chapters.manga_id
45+
) AS C
46+
ON M._id = C.manga_id
47+
LEFT JOIN (SELECT * FROM mangas_categories) AS MC
48+
ON MC.manga_id = M._id
49+
WHERE M.favorite = 1
50+
ORDER BY M.title;

data/src/commonMain/sqldelight/tachiyomi/view/library_view.sq

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ LEFT JOIN (
2121
FROM chapters
2222
LEFT JOIN scanlators_view AS filtered_scanlators
2323
ON chapters.manga_id = filtered_scanlators.manga_id
24-
AND ifnull(chapters.scanlator, 'N/A') = ifnull(filtered_scanlators.name, '/<INVALID>/') -- I assume if it's N/A it shouldn't be filtered
24+
AND chapters.scanlator = filtered_scanlators.name
2525
LEFT JOIN history
2626
ON chapters._id = history.history_chapter_id
2727
WHERE filtered_scanlators.name IS NULL

data/src/commonMain/sqldelight/tachiyomi/view/scanlators_view.sq

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ SELECT S.* FROM (
1010
substr(str, instr(str, ' [.] ')+5)
1111
FROM split WHERE str != ''
1212
)
13-
SELECT _id AS manga_id, name FROM split WHERE split.seq != 0 ORDER BY split.seq ASC
13+
SELECT _id AS manga_id, name FROM split WHERE name != '' ORDER BY split.seq ASC
1414
) AS S;

0 commit comments

Comments
 (0)