mirror of
https://github.com/gotson/komga.git
synced 2025-01-09 04:08:00 +08: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
@ -342,7 +342,7 @@ export default Vue.extend({
|
||||
}, 5000),
|
||||
setupLoaders(libraryId: string) {
|
||||
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]),
|
||||
)
|
||||
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)),
|
||||
)
|
||||
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]),
|
||||
)
|
||||
|
||||
@ -377,7 +377,7 @@ export default Vue.extend({
|
||||
this.selectedSeries = []
|
||||
this.selectedBooks = []
|
||||
|
||||
if(reload){
|
||||
if (reload) {
|
||||
Promise.all([
|
||||
this.loaderInProgressBooks.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 page: Int,
|
||||
val completed: Boolean,
|
||||
val readDate: LocalDateTime = LocalDateTime.now(),
|
||||
|
||||
override val createdDate: LocalDateTime = LocalDateTime.now(),
|
||||
override val lastModifiedDate: LocalDateTime = LocalDateTime.now()
|
||||
|
@ -70,6 +70,7 @@ class BookDtoDao(
|
||||
"metadata.numberSort" to d.NUMBER_SORT,
|
||||
"metadata.releaseDate" to d.RELEASE_DATE,
|
||||
"readProgress.lastModified" to r.LAST_MODIFIED_DATE,
|
||||
"readProgress.readDate" to r.READ_DATE,
|
||||
"readList.number" to rlb.NUMBER,
|
||||
)
|
||||
|
||||
@ -381,6 +382,7 @@ class BookDtoDao(
|
||||
ReadProgressDto(
|
||||
page = page,
|
||||
completed = completed,
|
||||
readDate = readDate,
|
||||
created = createdDate,
|
||||
lastModified = lastModifiedDate
|
||||
)
|
||||
|
@ -2,6 +2,7 @@ package org.gotson.komga.infrastructure.jooq
|
||||
|
||||
import org.gotson.komga.domain.model.ReadProgress
|
||||
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.records.ReadProgressRecord
|
||||
import org.jooq.DSLContext
|
||||
@ -9,6 +10,8 @@ import org.jooq.Query
|
||||
import org.jooq.impl.DSL
|
||||
import org.springframework.stereotype.Component
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
|
||||
@Component
|
||||
class ReadProgressDao(
|
||||
@ -66,12 +69,26 @@ class ReadProgressDao(
|
||||
}
|
||||
|
||||
private fun saveQuery(readProgress: ReadProgress): Query =
|
||||
dsl.insertInto(r, r.BOOK_ID, r.USER_ID, r.PAGE, r.COMPLETED)
|
||||
.values(readProgress.bookId, readProgress.userId, readProgress.page, readProgress.completed)
|
||||
dsl.insertInto(
|
||||
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()
|
||||
.set(r.PAGE, readProgress.page)
|
||||
.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
|
||||
override fun delete(bookId: String, userId: String) {
|
||||
@ -143,6 +160,7 @@ class ReadProgressDao(
|
||||
userId = userId,
|
||||
page = page,
|
||||
completed = completed,
|
||||
readDate = readDate.toCurrentTimeZone(),
|
||||
createdDate = createdDate.toCurrentTimeZone(),
|
||||
lastModifiedDate = lastModifiedDate.toCurrentTimeZone()
|
||||
)
|
||||
|
@ -66,6 +66,8 @@ data class ReadProgressDto(
|
||||
val page: Int,
|
||||
val completed: Boolean,
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
|
||||
val readDate: LocalDateTime,
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
|
||||
val created: LocalDateTime,
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
|
||||
val lastModified: LocalDateTime
|
||||
|
@ -81,9 +81,10 @@ class ReadProgressDaoTest(
|
||||
assertThat(page).isEqualTo(5)
|
||||
assertThat(completed).isEqualTo(false)
|
||||
assertThat(bookId).isEqualTo(book1.id)
|
||||
assertThat(readDate).isCloseTo(now, offset)
|
||||
assertThat(createdDate)
|
||||
.isCloseTo(now, offset)
|
||||
.isEqualTo(lastModifiedDate)
|
||||
.isEqualToIgnoringNanos(lastModifiedDate)
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,6 +100,7 @@ class ReadProgressDaoTest(
|
||||
)
|
||||
|
||||
val modificationDate = LocalDateTime.now()
|
||||
val readDateInThePast = LocalDateTime.now().minusYears(1)
|
||||
|
||||
readProgressDao.save(
|
||||
ReadProgress(
|
||||
@ -106,7 +108,7 @@ class ReadProgressDaoTest(
|
||||
user1.id,
|
||||
10,
|
||||
true,
|
||||
lastModifiedDate = modificationDate,
|
||||
readDate = readDateInThePast,
|
||||
)
|
||||
)
|
||||
|
||||
@ -117,6 +119,7 @@ class ReadProgressDaoTest(
|
||||
assertThat(page).isEqualTo(10)
|
||||
assertThat(completed).isEqualTo(true)
|
||||
assertThat(bookId).isEqualTo(book1.id)
|
||||
assertThat(readDate).isEqualTo(readDateInThePast)
|
||||
assertThat(createdDate)
|
||||
.isBefore(modificationDate)
|
||||
.isNotEqualTo(lastModifiedDate)
|
||||
|
Loading…
Reference in New Issue
Block a user