mirror of
https://github.com/gotson/komga.git
synced 2026-05-09 05:10:19 +02:00
fix: don't update read progress data upon upgrade or restore
add readDate to ReadProgress instead of relying on lastModifiedDate
This commit is contained in:
parent
49ebb7457a
commit
72d3451140
7 changed files with 55 additions and 8 deletions
|
|
@ -342,7 +342,7 @@ export default Vue.extend({
|
||||||
}, 5000),
|
}, 5000),
|
||||||
setupLoaders(libraryId: string) {
|
setupLoaders(libraryId: string) {
|
||||||
this.loaderInProgressBooks = new PageLoader<BookDto>(
|
this.loaderInProgressBooks = new PageLoader<BookDto>(
|
||||||
{sort: ['readProgress.lastModified,desc']},
|
{sort: ['readProgress.readDate,desc']},
|
||||||
(pageable: PageRequest) => this.$komgaBooks.getBooks(this.getRequestLibraryId(libraryId), pageable, undefined, undefined, [ReadStatus.IN_PROGRESS]),
|
(pageable: PageRequest) => this.$komgaBooks.getBooks(this.getRequestLibraryId(libraryId), pageable, undefined, undefined, [ReadStatus.IN_PROGRESS]),
|
||||||
)
|
)
|
||||||
this.loaderOnDeckBooks = new PageLoader<BookDto>(
|
this.loaderOnDeckBooks = new PageLoader<BookDto>(
|
||||||
|
|
@ -358,7 +358,7 @@ export default Vue.extend({
|
||||||
(pageable: PageRequest) => this.$komgaBooks.getBooks(this.getRequestLibraryId(libraryId), pageable, undefined, undefined, undefined, subMonths(new Date(), 1)),
|
(pageable: PageRequest) => this.$komgaBooks.getBooks(this.getRequestLibraryId(libraryId), pageable, undefined, undefined, undefined, subMonths(new Date(), 1)),
|
||||||
)
|
)
|
||||||
this.loaderRecentlyReadBooks = new PageLoader<BookDto>(
|
this.loaderRecentlyReadBooks = new PageLoader<BookDto>(
|
||||||
{sort: ['readProgress.lastModified,desc']},
|
{sort: ['readProgress.readDate,desc']},
|
||||||
(pageable: PageRequest) => this.$komgaBooks.getBooks(this.getRequestLibraryId(libraryId), pageable, undefined, undefined, [ReadStatus.READ]),
|
(pageable: PageRequest) => this.$komgaBooks.getBooks(this.getRequestLibraryId(libraryId), pageable, undefined, undefined, [ReadStatus.READ]),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -377,7 +377,7 @@ export default Vue.extend({
|
||||||
this.selectedSeries = []
|
this.selectedSeries = []
|
||||||
this.selectedBooks = []
|
this.selectedBooks = []
|
||||||
|
|
||||||
if(reload){
|
if (reload) {
|
||||||
Promise.all([
|
Promise.all([
|
||||||
this.loaderInProgressBooks.reload(),
|
this.loaderInProgressBooks.reload(),
|
||||||
this.loaderOnDeckBooks.reload(),
|
this.loaderOnDeckBooks.reload(),
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
ALTER TABLE READ_PROGRESS RENAME TO TMP_READ_PROGRESS;
|
||||||
|
|
||||||
|
CREATE TABLE READ_PROGRESS
|
||||||
|
(
|
||||||
|
BOOK_ID varchar NOT NULL,
|
||||||
|
USER_ID varchar NOT NULL,
|
||||||
|
CREATED_DATE datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
LAST_MODIFIED_DATE datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
PAGE int NOT NULL,
|
||||||
|
COMPLETED boolean NOT NULL,
|
||||||
|
READ_DATE datetime NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (BOOK_ID, USER_ID),
|
||||||
|
FOREIGN KEY (BOOK_ID) REFERENCES BOOK (ID),
|
||||||
|
FOREIGN KEY (USER_ID) REFERENCES USER (ID)
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO READ_PROGRESS(BOOK_ID, USER_ID, CREATED_DATE, LAST_MODIFIED_DATE, PAGE, COMPLETED, READ_DATE)
|
||||||
|
SELECT BOOK_ID, USER_ID, CREATED_DATE, LAST_MODIFIED_DATE, PAGE, COMPLETED, LAST_MODIFIED_DATE
|
||||||
|
FROM TMP_READ_PROGRESS;
|
||||||
|
|
||||||
|
DROP TABLE TMP_READ_PROGRESS;
|
||||||
|
|
@ -8,6 +8,7 @@ data class ReadProgress(
|
||||||
val userId: String,
|
val userId: String,
|
||||||
val page: Int,
|
val page: Int,
|
||||||
val completed: Boolean,
|
val completed: Boolean,
|
||||||
|
val readDate: LocalDateTime = LocalDateTime.now(),
|
||||||
|
|
||||||
override val createdDate: LocalDateTime = LocalDateTime.now(),
|
override val createdDate: LocalDateTime = LocalDateTime.now(),
|
||||||
override val lastModifiedDate: LocalDateTime = LocalDateTime.now()
|
override val lastModifiedDate: LocalDateTime = LocalDateTime.now()
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ class BookDtoDao(
|
||||||
"metadata.numberSort" to d.NUMBER_SORT,
|
"metadata.numberSort" to d.NUMBER_SORT,
|
||||||
"metadata.releaseDate" to d.RELEASE_DATE,
|
"metadata.releaseDate" to d.RELEASE_DATE,
|
||||||
"readProgress.lastModified" to r.LAST_MODIFIED_DATE,
|
"readProgress.lastModified" to r.LAST_MODIFIED_DATE,
|
||||||
|
"readProgress.readDate" to r.READ_DATE,
|
||||||
"readList.number" to rlb.NUMBER,
|
"readList.number" to rlb.NUMBER,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -381,6 +382,7 @@ class BookDtoDao(
|
||||||
ReadProgressDto(
|
ReadProgressDto(
|
||||||
page = page,
|
page = page,
|
||||||
completed = completed,
|
completed = completed,
|
||||||
|
readDate = readDate,
|
||||||
created = createdDate,
|
created = createdDate,
|
||||||
lastModified = lastModifiedDate
|
lastModified = lastModifiedDate
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package org.gotson.komga.infrastructure.jooq
|
||||||
|
|
||||||
import org.gotson.komga.domain.model.ReadProgress
|
import org.gotson.komga.domain.model.ReadProgress
|
||||||
import org.gotson.komga.domain.persistence.ReadProgressRepository
|
import org.gotson.komga.domain.persistence.ReadProgressRepository
|
||||||
|
import org.gotson.komga.interfaces.rest.dto.toUTC
|
||||||
import org.gotson.komga.jooq.Tables
|
import org.gotson.komga.jooq.Tables
|
||||||
import org.gotson.komga.jooq.tables.records.ReadProgressRecord
|
import org.gotson.komga.jooq.tables.records.ReadProgressRecord
|
||||||
import org.jooq.DSLContext
|
import org.jooq.DSLContext
|
||||||
|
|
@ -9,6 +10,8 @@ import org.jooq.Query
|
||||||
import org.jooq.impl.DSL
|
import org.jooq.impl.DSL
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
import org.springframework.transaction.annotation.Transactional
|
import org.springframework.transaction.annotation.Transactional
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.ZoneId
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
class ReadProgressDao(
|
class ReadProgressDao(
|
||||||
|
|
@ -66,12 +69,26 @@ class ReadProgressDao(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveQuery(readProgress: ReadProgress): Query =
|
private fun saveQuery(readProgress: ReadProgress): Query =
|
||||||
dsl.insertInto(r, r.BOOK_ID, r.USER_ID, r.PAGE, r.COMPLETED)
|
dsl.insertInto(
|
||||||
.values(readProgress.bookId, readProgress.userId, readProgress.page, readProgress.completed)
|
r,
|
||||||
|
r.BOOK_ID,
|
||||||
|
r.USER_ID,
|
||||||
|
r.PAGE,
|
||||||
|
r.COMPLETED,
|
||||||
|
r.READ_DATE,
|
||||||
|
)
|
||||||
|
.values(
|
||||||
|
readProgress.bookId,
|
||||||
|
readProgress.userId,
|
||||||
|
readProgress.page,
|
||||||
|
readProgress.completed,
|
||||||
|
readProgress.readDate.toUTC(),
|
||||||
|
)
|
||||||
.onDuplicateKeyUpdate()
|
.onDuplicateKeyUpdate()
|
||||||
.set(r.PAGE, readProgress.page)
|
.set(r.PAGE, readProgress.page)
|
||||||
.set(r.COMPLETED, readProgress.completed)
|
.set(r.COMPLETED, readProgress.completed)
|
||||||
.set(r.LAST_MODIFIED_DATE, readProgress.lastModifiedDate.toUTC())
|
.set(r.READ_DATE, readProgress.readDate.toUTC())
|
||||||
|
.set(r.LAST_MODIFIED_DATE, LocalDateTime.now(ZoneId.of("Z")))
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
override fun delete(bookId: String, userId: String) {
|
override fun delete(bookId: String, userId: String) {
|
||||||
|
|
@ -143,6 +160,7 @@ class ReadProgressDao(
|
||||||
userId = userId,
|
userId = userId,
|
||||||
page = page,
|
page = page,
|
||||||
completed = completed,
|
completed = completed,
|
||||||
|
readDate = readDate.toCurrentTimeZone(),
|
||||||
createdDate = createdDate.toCurrentTimeZone(),
|
createdDate = createdDate.toCurrentTimeZone(),
|
||||||
lastModifiedDate = lastModifiedDate.toCurrentTimeZone()
|
lastModifiedDate = lastModifiedDate.toCurrentTimeZone()
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,8 @@ data class ReadProgressDto(
|
||||||
val page: Int,
|
val page: Int,
|
||||||
val completed: Boolean,
|
val completed: Boolean,
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
|
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
|
||||||
|
val readDate: LocalDateTime,
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
|
||||||
val created: LocalDateTime,
|
val created: LocalDateTime,
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
|
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
|
||||||
val lastModified: LocalDateTime
|
val lastModified: LocalDateTime
|
||||||
|
|
|
||||||
|
|
@ -81,9 +81,10 @@ class ReadProgressDaoTest(
|
||||||
assertThat(page).isEqualTo(5)
|
assertThat(page).isEqualTo(5)
|
||||||
assertThat(completed).isEqualTo(false)
|
assertThat(completed).isEqualTo(false)
|
||||||
assertThat(bookId).isEqualTo(book1.id)
|
assertThat(bookId).isEqualTo(book1.id)
|
||||||
|
assertThat(readDate).isCloseTo(now, offset)
|
||||||
assertThat(createdDate)
|
assertThat(createdDate)
|
||||||
.isCloseTo(now, offset)
|
.isCloseTo(now, offset)
|
||||||
.isEqualTo(lastModifiedDate)
|
.isEqualToIgnoringNanos(lastModifiedDate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,6 +100,7 @@ class ReadProgressDaoTest(
|
||||||
)
|
)
|
||||||
|
|
||||||
val modificationDate = LocalDateTime.now()
|
val modificationDate = LocalDateTime.now()
|
||||||
|
val readDateInThePast = LocalDateTime.now().minusYears(1)
|
||||||
|
|
||||||
readProgressDao.save(
|
readProgressDao.save(
|
||||||
ReadProgress(
|
ReadProgress(
|
||||||
|
|
@ -106,7 +108,7 @@ class ReadProgressDaoTest(
|
||||||
user1.id,
|
user1.id,
|
||||||
10,
|
10,
|
||||||
true,
|
true,
|
||||||
lastModifiedDate = modificationDate,
|
readDate = readDateInThePast,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -117,6 +119,7 @@ class ReadProgressDaoTest(
|
||||||
assertThat(page).isEqualTo(10)
|
assertThat(page).isEqualTo(10)
|
||||||
assertThat(completed).isEqualTo(true)
|
assertThat(completed).isEqualTo(true)
|
||||||
assertThat(bookId).isEqualTo(book1.id)
|
assertThat(bookId).isEqualTo(book1.id)
|
||||||
|
assertThat(readDate).isEqualTo(readDateInThePast)
|
||||||
assertThat(createdDate)
|
assertThat(createdDate)
|
||||||
.isBefore(modificationDate)
|
.isBefore(modificationDate)
|
||||||
.isNotEqualTo(lastModifiedDate)
|
.isNotEqualTo(lastModifiedDate)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue