mihonapp / mihon

Free and open source manga reader for Android
Apache License 2.0
10.5k stars 482 forks source link

[Question] Why the database does not have unique constraints? #647

Open Cologler opened 7 months ago

Cologler commented 7 months ago

Steps to reproduce

I have no idea where they come from. It might be because I'm refreshing the database while simultaneously importing data.

Expected behavior

The database is guarded by unique constraints.

Actual behavior

A lot of duplicated chapters:

image

Crash logs

No response

Mihon version

latest

Android version

12

Device

phone

Other details

Why the database does not have unique constraints like:

Some related issues:

Acknowledgements

Cologler commented 7 months ago

When two elements have the same key, if we query one from the database, it would be the first one; if we query all from the database and then map by associateBy(), it would be the last one.

This inconsistency leads to numerous issues.

Cologler commented 7 months ago

Even though the chapter_id of history has unique constraints, if the (manga_id, url) of chapter lacks unique constraints, then this is not unique:

https://github.com/mihonapp/mihon/blob/c94d212ef471012990bfe02ba43044de476ab9cd/app/src/main/java/eu/kanade/tachiyomi/data/backup/restore/restorers/MangaRestorer.kt#L323C13-L323C106

This issue can lead to restoration failure with:

// <-- this is in my tachiyomi_restore.txt
ResultSet returned more than 1 row for history.sq:getHistoryByChapterUrl

By the way, since this is a relative URL, it might be duplicated across different sources. TachiyomiSY has already tried to fix this issue by use mangaId: