Reader: Save reading progress with SQLDelight (#7185)

* Use SQLDelight in reader to update history

* Move chapter progress to sqldelight

* Review Changes

Co-Authored-By: inorichi <len@kanade.eu>

* Review Changes 2

Co-authored-by: FourTOne5 <59261191+FourTOne5@users.noreply.github.com>
Co-authored-by: inorichi <len@kanade.eu>
This commit is contained in:
AntsyLich
2022-05-28 19:09:27 +06:00
committed by GitHub
parent 6b14f38cfa
commit 809da49301
22 changed files with 309 additions and 67 deletions

View File

@ -26,4 +26,19 @@ WHERE _id = :id;
getChapterByMangaId:
SELECT *
FROM chapters
WHERE manga_id = :mangaId;
WHERE manga_id = :mangaId;
update:
UPDATE chapters
SET manga_id = coalesce(:mangaId, manga_id),
url = coalesce(:url, url),
name = coalesce(:name, name),
scanlator = coalesce(:scanlator, scanlator),
read = coalesce(:read, read),
bookmark = coalesce(:bookmark, bookmark),
last_page_read = coalesce(:lastPageRead, last_page_read),
chapter_number = coalesce(:chapterNumber, chapter_number),
source_order = coalesce(:sourceOrder, source_order),
date_fetch = coalesce(:dateFetch, date_fetch),
date_upload = coalesce(:dateUpload, date_upload)
WHERE _id = :chapterId;

View File

@ -1,31 +1,31 @@
import java.util.Date;
CREATE TABLE history(
history_id INTEGER NOT NULL PRIMARY KEY,
history_chapter_id INTEGER NOT NULL UNIQUE,
history_last_read INTEGER AS Date,
history_time_read INTEGER AS Date,
FOREIGN KEY(history_chapter_id) REFERENCES chapters (_id)
_id INTEGER NOT NULL PRIMARY KEY,
chapter_id INTEGER NOT NULL UNIQUE,
last_read INTEGER AS Date,
time_read INTEGER NOT NULL,
FOREIGN KEY(chapter_id) REFERENCES chapters (_id)
ON DELETE CASCADE
);
CREATE INDEX history_history_chapter_id_index ON history(history_chapter_id);
CREATE INDEX history_history_chapter_id_index ON history(chapter_id);
resetHistoryById:
UPDATE history
SET history_last_read = 0
WHERE history_id = :historyId;
SET last_read = 0
WHERE _id = :historyId;
resetHistoryByMangaId:
UPDATE history
SET history_last_read = 0
WHERE history_id IN (
SELECT H.history_id
SET last_read = 0
WHERE _id IN (
SELECT H._id
FROM mangas M
INNER JOIN chapters C
ON M._id = C.manga_id
INNER JOIN history H
ON C._id = H.history_chapter_id
ON C._id = H.chapter_id
WHERE M._id = :mangaId
);
@ -34,4 +34,14 @@ DELETE FROM history;
removeResettedHistory:
DELETE FROM history
WHERE history_last_read = 0;
WHERE last_read = 0;
insert:
INSERT INTO history(chapter_id, last_read, time_read)
VALUES (:chapterId, :readAt, :readDuration);
update:
UPDATE history
SET last_read = :readAt,
time_read = time_read + :sessionReadDuration
WHERE chapter_id = :chapterId;