diff --git a/data/db-sqldelight/src/commonMain/sqldelight/app/tivi/data/related_shows.sq b/data/db-sqldelight/src/commonMain/sqldelight/app/tivi/data/related_shows.sq index df73c9388f..2147b7fb6a 100644 --- a/data/db-sqldelight/src/commonMain/sqldelight/app/tivi/data/related_shows.sq +++ b/data/db-sqldelight/src/commonMain/sqldelight/app/tivi/data/related_shows.sq @@ -13,6 +13,8 @@ CREATE INDEX IF NOT EXISTS `index_related_shows_show_id` ON `related_shows` (`sh CREATE INDEX IF NOT EXISTS `index_related_shows_other_show_id` ON `related_shows` (`other_show_id`); +CREATE UNIQUE INDEX IF NOT EXISTS `index_related_shows_unique` ON `related_shows` (`show_id`, `other_show_id`); + -- queries entries: diff --git a/data/db-sqldelight/src/commonMain/sqldelight/migrations/33.sqm b/data/db-sqldelight/src/commonMain/sqldelight/migrations/33.sqm new file mode 100644 index 0000000000..fe78f15163 --- /dev/null +++ b/data/db-sqldelight/src/commonMain/sqldelight/migrations/33.sqm @@ -0,0 +1,10 @@ + +-- delete duplicate related shows +DELETE FROM `related_shows` WHERE rowid NOT IN ( + SELECT MIN(rowid) + FROM related_shows + GROUP BY show_id, other_show_id +); + +-- finally add an index to make sure this doesn't happen in the future +CREATE UNIQUE INDEX IF NOT EXISTS `index_related_shows_unique` ON `related_shows` (`show_id`, `other_show_id`); diff --git a/data/relatedshows/src/commonMain/kotlin/app/tivi/data/relatedshows/RelatedShowsStore.kt b/data/relatedshows/src/commonMain/kotlin/app/tivi/data/relatedshows/RelatedShowsStore.kt index 05c5d45f13..19f0bafb94 100644 --- a/data/relatedshows/src/commonMain/kotlin/app/tivi/data/relatedshows/RelatedShowsStore.kt +++ b/data/relatedshows/src/commonMain/kotlin/app/tivi/data/relatedshows/RelatedShowsStore.kt @@ -52,7 +52,7 @@ class RelatedShowsStore( showId = showId, otherShowId = showDao.getIdOrSavePlaceholder(show), ) - } + }.distinctBy { it.otherShowId } } } }