mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-17 16:49:43 +02:00
Optimize and cleanup library code (#2329)
This commit is contained in:
@@ -92,7 +92,7 @@ object MangaMapper {
|
||||
chapterFetchedAt: Long,
|
||||
lastRead: Long,
|
||||
bookmarkCount: Double,
|
||||
category: Long,
|
||||
categories: String,
|
||||
): LibraryManga = LibraryManga(
|
||||
manga = mapManga(
|
||||
id,
|
||||
@@ -121,7 +121,7 @@ object MangaMapper {
|
||||
isSyncing,
|
||||
notes,
|
||||
),
|
||||
category = category,
|
||||
categories = categories.split(",").map { it.toLong() },
|
||||
totalChapters = totalCount,
|
||||
readCount = readCount.toLong(),
|
||||
bookmarkCount = bookmarkCount.toLong(),
|
||||
|
39
data/src/main/sqldelight/tachiyomi/migrations/6.sqm
Normal file
39
data/src/main/sqldelight/tachiyomi/migrations/6.sqm
Normal file
@@ -0,0 +1,39 @@
|
||||
DROP VIEW IF EXISTS libraryView;
|
||||
|
||||
CREATE VIEW libraryView AS
|
||||
SELECT
|
||||
M.*,
|
||||
coalesce(C.total, 0) AS totalCount,
|
||||
coalesce(C.readCount, 0) AS readCount,
|
||||
coalesce(C.latestUpload, 0) AS latestUpload,
|
||||
coalesce(C.fetchedAt, 0) AS chapterFetchedAt,
|
||||
coalesce(C.lastRead, 0) AS lastRead,
|
||||
coalesce(C.bookmarkCount, 0) AS bookmarkCount,
|
||||
coalesce(MC.categories, '0') AS categories
|
||||
FROM mangas M
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
chapters.manga_id,
|
||||
count(*) AS total,
|
||||
sum(read) AS readCount,
|
||||
coalesce(max(chapters.date_upload), 0) AS latestUpload,
|
||||
coalesce(max(history.last_read), 0) AS lastRead,
|
||||
coalesce(max(chapters.date_fetch), 0) AS fetchedAt,
|
||||
sum(chapters.bookmark) AS bookmarkCount
|
||||
FROM chapters
|
||||
LEFT JOIN excluded_scanlators
|
||||
ON chapters.manga_id = excluded_scanlators.manga_id
|
||||
AND chapters.scanlator = excluded_scanlators.scanlator
|
||||
LEFT JOIN history
|
||||
ON chapters._id = history.chapter_id
|
||||
WHERE excluded_scanlators.scanlator IS NULL
|
||||
GROUP BY chapters.manga_id
|
||||
) AS C
|
||||
ON M._id = C.manga_id
|
||||
LEFT JOIN (
|
||||
SELECT manga_id, group_concat(category_id) AS categories
|
||||
FROM mangas_categories
|
||||
GROUP BY manga_id
|
||||
) AS MC
|
||||
ON MC.manga_id = M._id
|
||||
WHERE M.favorite = 1;
|
@@ -7,9 +7,9 @@ SELECT
|
||||
coalesce(C.fetchedAt, 0) AS chapterFetchedAt,
|
||||
coalesce(C.lastRead, 0) AS lastRead,
|
||||
coalesce(C.bookmarkCount, 0) AS bookmarkCount,
|
||||
coalesce(MC.category_id, 0) AS category
|
||||
coalesce(MC.categories, '0') AS categories
|
||||
FROM mangas M
|
||||
LEFT JOIN(
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
chapters.manga_id,
|
||||
count(*) AS total,
|
||||
@@ -28,7 +28,11 @@ LEFT JOIN(
|
||||
GROUP BY chapters.manga_id
|
||||
) AS C
|
||||
ON M._id = C.manga_id
|
||||
LEFT JOIN mangas_categories AS MC
|
||||
LEFT JOIN (
|
||||
SELECT manga_id, group_concat(category_id) AS categories
|
||||
FROM mangas_categories
|
||||
GROUP BY manga_id
|
||||
) AS MC
|
||||
ON MC.manga_id = M._id
|
||||
WHERE M.favorite = 1;
|
||||
|
||||
|
Reference in New Issue
Block a user