Skip to content

Commit

Permalink
deduplicate tags and genres
Browse files Browse the repository at this point in the history
  • Loading branch information
Snd-R committed Sep 20, 2023
1 parent 2086cf9 commit 8799843
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ fun MediaServerSeriesMetadataUpdate.kavitaSeriesMetadataUpdate(oldMeta: KavitaSe
publicationStatus = status ?: oldMeta.publicationStatus,
summary = summary ?: oldMeta.summary,
publishers = publishers,
genres = genres?.map { KavitaGenre(id = 0, title = it) }?.toSet() ?: oldMeta.genres,
tags = tags?.map { KavitaTag(id = 0, title = it) }?.toSet() ?: oldMeta.tags,
genres = genres?.let { deduplicate(it) }?.map { KavitaGenre(id = 0, title = it) }?.toSet() ?: oldMeta.genres,
tags = tags?.let { deduplicate(it) }?.map { KavitaTag(id = 0, title = it) }?.toSet() ?: oldMeta.tags,
writers = authors
?.get(AuthorRole.WRITER.name.lowercase())
?.map { KavitaAuthor(id = 0, name = it.name, role = WRITER) }?.toSet()
Expand Down Expand Up @@ -91,6 +91,12 @@ fun MediaServerSeriesMetadataUpdate.kavitaSeriesMetadataUpdate(oldMeta: KavitaSe
return KavitaSeriesMetadataUpdate(metadata, collectionTags)
}

private val normalizeRegex = "[^\\p{L}0-9+!]".toRegex()
private fun deduplicate(values: Collection<String>) = values
.map { normalizeRegex.replace(it, "").trim().lowercase() to it }
.distinctBy { (normalized, _) -> normalized }
.map { (_, value) -> value }

fun kavitaSeriesResetRequest(seriesId: KavitaSeriesId): KavitaSeriesMetadataUpdate {
val metadata = KavitaSeriesMetadata(
id = 0,
Expand Down

0 comments on commit 8799843

Please sign in to comment.