From 7e6e19089f21d73066bea441d7b3140bcfdacee4 Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Fri, 3 Jan 2020 17:24:03 +0800 Subject: [PATCH] refactor: http caching for images depends on media analysis instead of the file last modified date will help for #51 --- .../kotlin/org/gotson/komga/domain/model/Media.kt | 2 +- .../komga/interfaces/web/rest/BookController.kt | 2 +- .../V20200103170613__media_as_auditable_entity.sql | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 komga/src/main/resources/db/migration/V20200103170613__media_as_auditable_entity.sql diff --git a/komga/src/main/kotlin/org/gotson/komga/domain/model/Media.kt b/komga/src/main/kotlin/org/gotson/komga/domain/model/Media.kt index 909a453b1..f5442e94d 100644 --- a/komga/src/main/kotlin/org/gotson/komga/domain/model/Media.kt +++ b/komga/src/main/kotlin/org/gotson/komga/domain/model/Media.kt @@ -38,7 +38,7 @@ class Media( var thumbnail: ByteArray? = null, pages: Iterable = emptyList() -) { +) : AuditableEntity() { @Id @GeneratedValue @Column(name = "id", nullable = false, unique = true) diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/web/rest/BookController.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/web/rest/BookController.kt index e07eb693e..a69b8e8fd 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/web/rest/BookController.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/web/rest/BookController.kt @@ -238,7 +238,7 @@ class BookController( ).lastModified(getBookLastModified(book)) private fun getBookLastModified(book: Book) = - book.fileLastModified.toInstant(ZoneOffset.UTC).toEpochMilli() + book.media.lastModifiedDate!!.toInstant(ZoneOffset.UTC).toEpochMilli() private fun getMediaTypeOrDefault(mediaTypeString: String?): MediaType { diff --git a/komga/src/main/resources/db/migration/V20200103170613__media_as_auditable_entity.sql b/komga/src/main/resources/db/migration/V20200103170613__media_as_auditable_entity.sql new file mode 100644 index 000000000..f7f3d7d14 --- /dev/null +++ b/komga/src/main/resources/db/migration/V20200103170613__media_as_auditable_entity.sql @@ -0,0 +1,13 @@ +alter table media + add (created_date timestamp); +alter table media + add (last_modified_date timestamp); + +update media +set created_date = CURRENT_TIMESTAMP(), + last_modified_date = CURRENT_TIMESTAMP(); + +alter table media + alter column created_date set not null; +alter table media + alter column last_modified_date set not null;