From bf1903bc3a16d916784596af2c05e527ea276620 Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Tue, 27 Jun 2023 11:45:12 +0800 Subject: [PATCH] feat: add match count sort for known duplicate pages Closes: #825 --- .../src/components/PageHashKnownCard.vue | 23 ++++++------------- komga-webui/src/locales/en.json | 3 ++- komga-webui/src/types/komga-pagehashes.ts | 2 +- komga-webui/src/views/DuplicatePagesKnown.vue | 1 + .../komga/domain/model/PageHashKnown.kt | 3 +++ .../komga/infrastructure/jooq/PageHashDao.kt | 13 +++++++---- .../api/rest/dto/PageHashKnownDto.kt | 2 ++ 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/komga-webui/src/components/PageHashKnownCard.vue b/komga-webui/src/components/PageHashKnownCard.vue index 68f2d0ce..dca694d8 100644 --- a/komga-webui/src/components/PageHashKnownCard.vue +++ b/komga-webui/src/components/PageHashKnownCard.vue @@ -34,12 +34,11 @@ - {{ $tc('duplicate_pages.matches_n', matchCount) }} + {{ $tc('duplicate_pages.matches_n', hash.matchCount) }} @@ -55,6 +54,11 @@ v-if="hash.size && hash.deleteCount" >{{ $t('duplicate_pages.saved_size', {size: getFileSize(hash.size * hash.deleteCount)}) }} + +

{{ $t('duplicate_pages.delete_to_save', {size: getFileSize(hash.size * hash.matchCount)}) }} +
@@ -66,7 +70,7 @@ mdi-check @@ -106,7 +110,6 @@ export default Vue.extend({ pageHashKnownThumbnailUrl, getFileSize, PageHashAction, - matchCount: undefined as number | undefined, deleteRequested: false, } }, @@ -122,26 +125,15 @@ export default Vue.extend({ } }, }, - mounted() { - this.getMatchCount() - }, watch: { hash: { handler() { this.deleteRequested = false - this.matchCount = undefined - this.getMatchCount() }, deep: true, }, }, methods: { - async getMatchCount() { - if (this.hash?.action === PageHashAction.DELETE_MANUAL) - this.matchCount = (await this.$komgaPageHashes.getPageHashMatches(this.hash, {size: 0})).totalElements - else - this.matchCount = undefined - }, async deleteMatches() { if(!this.deleteRequested) { await this.$komgaPageHashes.deleteAllMatches(this.hash) @@ -161,7 +153,6 @@ export default Vue.extend({ try { const p = { hash: this.hash.hash, - mediaType: this.hash.mediaType, size: this.hash.size, action: action, } diff --git a/komga-webui/src/locales/en.json b/komga-webui/src/locales/en.json index 88710dd0..7c0e6de4 100644 --- a/komga-webui/src/locales/en.json +++ b/komga-webui/src/locales/en.json @@ -591,7 +591,8 @@ "delete_count": "Deletion count", "delete_size": "Space saved", "size": "Size", - "total_size": "Total size" + "total_size": "Total size", + "match_count": "Match count" }, "info": "Deleting duplicate pages will modify your files. Backup your files and use manual deletion before using automatic deletion.", "known": "Known", diff --git a/komga-webui/src/types/komga-pagehashes.ts b/komga-webui/src/types/komga-pagehashes.ts index b5587331..28a9e863 100644 --- a/komga-webui/src/types/komga-pagehashes.ts +++ b/komga-webui/src/types/komga-pagehashes.ts @@ -3,10 +3,10 @@ import {PageHashAction} from '@/types/enum-pagehashes' export interface PageHashDto { hash: string, size?: number, + matchCount: number, } export interface PageHashUnknownDto extends PageHashDto { - matchCount: number, } export interface PageHashMatchDto { diff --git a/komga-webui/src/views/DuplicatePagesKnown.vue b/komga-webui/src/views/DuplicatePagesKnown.vue index 30f5d569..0392d138 100644 --- a/komga-webui/src/views/DuplicatePagesKnown.vue +++ b/komga-webui/src/views/DuplicatePagesKnown.vue @@ -162,6 +162,7 @@ export default Vue.extend({ {name: this.$t('duplicate_pages.filter.delete_size').toString(), key: 'deleteSize'}, {name: this.$t('duplicate_pages.filter.size').toString(), key: 'fileSize'}, {name: this.$t('duplicate_pages.filter.delete_count').toString(), key: 'deleteCount'}, + {name: this.$t('duplicate_pages.filter.match_count').toString(), key: 'matchCount'}, ] }, paginationVisible(): number { diff --git a/komga/src/main/kotlin/org/gotson/komga/domain/model/PageHashKnown.kt b/komga/src/main/kotlin/org/gotson/komga/domain/model/PageHashKnown.kt index efed80fe..4d30e28c 100644 --- a/komga/src/main/kotlin/org/gotson/komga/domain/model/PageHashKnown.kt +++ b/komga/src/main/kotlin/org/gotson/komga/domain/model/PageHashKnown.kt @@ -7,6 +7,7 @@ class PageHashKnown( size: Long? = null, val action: Action, val deleteCount: Int = 0, + val matchCount: Int = 0, override val createdDate: LocalDateTime = LocalDateTime.now(), override val lastModifiedDate: LocalDateTime = createdDate, @@ -22,10 +23,12 @@ class PageHashKnown( size: Long? = this.size, action: Action = this.action, deleteCount: Int = this.deleteCount, + matchCount: Int = this.matchCount, ) = PageHashKnown( hash = hash, size = size, action = action, deleteCount = deleteCount, + matchCount = matchCount, ) } diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/PageHashDao.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/PageHashDao.kt index 11a041d8..4b9e5197 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/PageHashDao.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/PageHashDao.kt @@ -32,8 +32,7 @@ class PageHashDao( private val sortsKnown = mapOf( "hash" to ph.HASH, - "mediatype" to ph.MEDIA_TYPE, - "fileSize" to ph.SIZE, + "matchCount" to DSL.field("count"), "deleteCount" to ph.DELETE_COUNT, "deleteSize" to ph.SIZE * ph.DELETE_COUNT, ) @@ -55,8 +54,11 @@ class PageHashDao( ?.toDomain() override fun findAllKnown(actions: List?, pageable: Pageable): Page { - val query = dsl.selectFrom(ph) + val query = dsl.select(*ph.fields(), DSL.count(p.FILE_HASH).`as`("count")) + .from(ph) + .leftJoin(p).on(ph.HASH.eq(p.FILE_HASH)) .apply { actions?.let { where(ph.ACTION.`in`(actions)) } } + .groupBy(*ph.fields()) val count = dsl.fetchCount(query) @@ -65,7 +67,7 @@ class PageHashDao( .orderBy(orderBy) .apply { if (pageable.isPaged) limit(pageable.pageSize).offset(pageable.offset) } .fetch() - .map { it.toDomain() } + .map { it.into(ph).toDomain(it.get("count", Int::class.java)) } val pageSort = if (orderBy.isNotEmpty()) pageable.sort else Sort.unsorted() return PageImpl( @@ -198,11 +200,12 @@ class PageHashDao( } } -private fun PageHashRecord.toDomain() = +private fun PageHashRecord.toDomain(matchCount: Int = 0) = PageHashKnown( hash = hash, size = size, deleteCount = deleteCount, + matchCount = matchCount, action = PageHashKnown.Action.valueOf(action), createdDate = createdDate.toCurrentTimeZone(), lastModifiedDate = lastModifiedDate.toCurrentTimeZone(), diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/api/rest/dto/PageHashKnownDto.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/api/rest/dto/PageHashKnownDto.kt index 014edc77..c3ca2f85 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/api/rest/dto/PageHashKnownDto.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/api/rest/dto/PageHashKnownDto.kt @@ -9,6 +9,7 @@ data class PageHashKnownDto( val size: Long?, val action: PageHashKnown.Action, val deleteCount: Int, + val matchCount: Int, val created: LocalDateTime, val lastModified: LocalDateTime, @@ -19,6 +20,7 @@ fun PageHashKnown.toDto() = PageHashKnownDto( size = size, action = action, deleteCount = deleteCount, + matchCount = matchCount, created = createdDate.toUTC(), lastModified = lastModifiedDate.toUTC(), )