Utilize tracker for library duplicate detection (mihonapp/mihon#2978)

* Utilize tracker for library duplicate detection (#2978)

Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
(cherry picked from commit 89bbdb17fb4ed1cbe99c14f389940e0f91093a10)

* Avoid crash due to duplicate manga ID when there are more than 1 trackers

* Add index for duplicate library manga detection in manga_sync

---------

Co-authored-by: Cuong-Tran <16017808+cuong-tran@users.noreply.github.com>
This commit is contained in:
NarwhalHorns 2026-02-21 10:26:36 +00:00 committed by Cuong-Tran
parent c290472012
commit e50767709a
4 changed files with 20 additions and 3 deletions

View file

@ -25,6 +25,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
- Reword download reindexing message to avoid confusion ([@MajorTanya](https://github.com/MajorTanya)) ([#2874](https://github.com/mihonapp/mihon/pull/2874)) - Reword download reindexing message to avoid confusion ([@MajorTanya](https://github.com/MajorTanya)) ([#2874](https://github.com/mihonapp/mihon/pull/2874))
- Rework internals for better performance ([@Lolle2000la](https://github.com/Lolle2000la)) ([#2955](https://github.com/mihonapp/mihon/pull/2955)) - Rework internals for better performance ([@Lolle2000la](https://github.com/Lolle2000la)) ([#2955](https://github.com/mihonapp/mihon/pull/2955))
- Optimize tracked library filter ([@NarwhalHorns](https://github.com/NarwhalHorns)) ([#2977](https://github.com/mihonapp/mihon/pull/2977)) - Optimize tracked library filter ([@NarwhalHorns](https://github.com/NarwhalHorns)) ([#2977](https://github.com/mihonapp/mihon/pull/2977))
- Utilize tracker for library duplicate detection ([@NarwhalHorns](https://github.com/NarwhalHorns)) ([#2977](https://github.com/mihonapp/mihon/pull/2978))
### Changed ### Changed
- Update tracker icons ([@AntsyLich](https://github.com/AntsyLich)) ([#2773](https://github.com/mihonapp/mihon/pull/2773)) - Update tracker icons ([@AntsyLich](https://github.com/AntsyLich)) ([#2773](https://github.com/mihonapp/mihon/pull/2773))

View file

@ -20,6 +20,9 @@ CREATE TABLE manga_sync(
ON DELETE CASCADE ON DELETE CASCADE
); );
-- KMK: index for mangas.sq: getDuplicateLibraryManga's track_dupes
CREATE INDEX idx_manga_sync_sync_id_remote_id ON manga_sync(sync_id, remote_id, manga_id);
delete: delete:
DELETE FROM manga_sync DELETE FROM manga_sync
WHERE manga_id = :mangaId AND sync_id = :syncId; WHERE manga_id = :mangaId AND sync_id = :syncId;

View file

@ -119,12 +119,23 @@ AND source = :sourceId;
getDuplicateLibraryManga: getDuplicateLibraryManga:
WITH WITH
track_dupes AS (
SELECT DISTINCT S2.manga_id
FROM manga_sync S1
INNER JOIN manga_sync S2
ON S1.sync_id = S2.sync_id
AND S1.remote_id = S2.remote_id
AND S1.manga_id != S2.manga_id
WHERE S1.manga_id = :id
),
duplicates AS ( duplicates AS (
SELECT * SELECT M.*
FROM mangas FROM mangas M
LEFT JOIN track_dupes D
ON D.manga_id = _id
WHERE favorite = 1 WHERE favorite = 1
AND _id != :id AND _id != :id
AND lower(title) LIKE '%' || lower(:title) || '%' AND (lower(title) LIKE '%' || lower(:title) || '%' OR D.manga_id IS NOT NULL)
), ),
chapter_counts AS ( chapter_counts AS (
SELECT SELECT

View file

@ -7,3 +7,5 @@ CREATE INDEX IF NOT EXISTS idx_mangas_categories_category_id ON mangas_categorie
DROP INDEX IF EXISTS excluded_scanlators_manga_id_index; DROP INDEX IF EXISTS excluded_scanlators_manga_id_index;
CREATE INDEX IF NOT EXISTS idx_excluded_scanlators_manga_id_scanlator ON excluded_scanlators(manga_id, scanlator); CREATE INDEX IF NOT EXISTS idx_excluded_scanlators_manga_id_scanlator ON excluded_scanlators(manga_id, scanlator);
CREATE INDEX IF NOT EXISTS idx_history_last_read ON history(last_read) WHERE last_read > 0; CREATE INDEX IF NOT EXISTS idx_history_last_read ON history(last_read) WHERE last_read > 0;
CREATE INDEX IF NOT EXISTS idx_manga_sync_sync_id_remote_id ON manga_sync(sync_id, remote_id, manga_id);