mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 09:01:49 +01:00
Better Upload Date to not have a single blank upload date. (#6358)
This commit is contained in:
parent
9e83130bd8
commit
a09d6c0470
@ -20,7 +20,7 @@ class DbOpenCallback : SupportSQLiteOpenHelper.Callback(DATABASE_VERSION) {
|
|||||||
/**
|
/**
|
||||||
* Version of the database.
|
* Version of the database.
|
||||||
*/
|
*/
|
||||||
const val DATABASE_VERSION = 13
|
const val DATABASE_VERSION = 14
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate(db: SupportSQLiteDatabase) = with(db) {
|
override fun onCreate(db: SupportSQLiteDatabase) = with(db) {
|
||||||
@ -91,6 +91,9 @@ class DbOpenCallback : SupportSQLiteOpenHelper.Callback(DATABASE_VERSION) {
|
|||||||
db.execSQL(TrackTable.insertFromTempTable)
|
db.execSQL(TrackTable.insertFromTempTable)
|
||||||
db.execSQL(TrackTable.dropTempTable)
|
db.execSQL(TrackTable.dropTempTable)
|
||||||
}
|
}
|
||||||
|
if (oldVersion < 14) {
|
||||||
|
db.execSQL(ChapterTable.fixDateUploadIfNeeded)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onConfigure(db: SupportSQLiteDatabase) {
|
override fun onConfigure(db: SupportSQLiteDatabase) {
|
||||||
|
@ -62,4 +62,7 @@ object ChapterTable {
|
|||||||
|
|
||||||
val addScanlator: String
|
val addScanlator: String
|
||||||
get() = "ALTER TABLE $TABLE ADD COLUMN $COL_SCANLATOR TEXT DEFAULT NULL"
|
get() = "ALTER TABLE $TABLE ADD COLUMN $COL_SCANLATOR TEXT DEFAULT NULL"
|
||||||
|
|
||||||
|
val fixDateUploadIfNeeded: String
|
||||||
|
get() = "UPDATE $TABLE SET $COL_DATE_UPLOAD = $COL_DATE_FETCH WHERE $COL_DATE_UPLOAD = 0"
|
||||||
}
|
}
|
||||||
|
@ -52,49 +52,46 @@ fun syncChaptersWithSource(
|
|||||||
// Chapters whose metadata have changed.
|
// Chapters whose metadata have changed.
|
||||||
val toChange = mutableListOf<Chapter>()
|
val toChange = mutableListOf<Chapter>()
|
||||||
|
|
||||||
|
// Chapters from the db not in source.
|
||||||
|
val toDelete = dbChapters.filterNot { dbChapter ->
|
||||||
|
sourceChapters.any { sourceChapter ->
|
||||||
|
dbChapter.url == sourceChapter.url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (sourceChapter in sourceChapters) {
|
for (sourceChapter in sourceChapters) {
|
||||||
|
// This forces metadata update for the main viewable things in the chapter list.
|
||||||
|
if (source is HttpSource) {
|
||||||
|
source.prepareNewChapter(sourceChapter, manga)
|
||||||
|
}
|
||||||
|
// Recognize chapter number for the chapter.
|
||||||
|
ChapterRecognition.parseChapterNumber(sourceChapter, manga)
|
||||||
|
|
||||||
val dbChapter = dbChapters.find { it.url == sourceChapter.url }
|
val dbChapter = dbChapters.find { it.url == sourceChapter.url }
|
||||||
|
|
||||||
// Add the chapter if not in db already, or update if the metadata changed.
|
// Add the chapter if not in db already, or update if the metadata changed.
|
||||||
if (dbChapter == null) {
|
if (dbChapter == null) {
|
||||||
|
if (sourceChapter.date_upload == 0L) {
|
||||||
|
sourceChapter.date_upload = Date().time
|
||||||
|
}
|
||||||
toAdd.add(sourceChapter)
|
toAdd.add(sourceChapter)
|
||||||
} else {
|
} else {
|
||||||
// this forces metadata update for the main viewable things in the chapter list
|
|
||||||
if (source is HttpSource) {
|
|
||||||
source.prepareNewChapter(sourceChapter, manga)
|
|
||||||
}
|
|
||||||
|
|
||||||
ChapterRecognition.parseChapterNumber(sourceChapter, manga)
|
|
||||||
|
|
||||||
if (shouldUpdateDbChapter(dbChapter, sourceChapter)) {
|
if (shouldUpdateDbChapter(dbChapter, sourceChapter)) {
|
||||||
if (dbChapter.name != sourceChapter.name && downloadManager.isChapterDownloaded(dbChapter, manga)) {
|
if (dbChapter.name != sourceChapter.name && downloadManager.isChapterDownloaded(dbChapter, manga)) {
|
||||||
downloadManager.renameChapter(source, manga, dbChapter, sourceChapter)
|
downloadManager.renameChapter(source, manga, dbChapter, sourceChapter)
|
||||||
}
|
}
|
||||||
dbChapter.scanlator = sourceChapter.scanlator
|
dbChapter.scanlator = sourceChapter.scanlator
|
||||||
dbChapter.name = sourceChapter.name
|
dbChapter.name = sourceChapter.name
|
||||||
dbChapter.date_upload = sourceChapter.date_upload
|
|
||||||
dbChapter.chapter_number = sourceChapter.chapter_number
|
dbChapter.chapter_number = sourceChapter.chapter_number
|
||||||
dbChapter.source_order = sourceChapter.source_order
|
dbChapter.source_order = sourceChapter.source_order
|
||||||
|
if (sourceChapter.date_upload != 0L) {
|
||||||
|
dbChapter.date_upload = sourceChapter.date_upload
|
||||||
|
}
|
||||||
toChange.add(dbChapter)
|
toChange.add(dbChapter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recognize number for new chapters.
|
|
||||||
toAdd.forEach {
|
|
||||||
if (source is HttpSource) {
|
|
||||||
source.prepareNewChapter(it, manga)
|
|
||||||
}
|
|
||||||
ChapterRecognition.parseChapterNumber(it, manga)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Chapters from the db not in the source.
|
|
||||||
val toDelete = dbChapters.filterNot { dbChapter ->
|
|
||||||
sourceChapters.any { sourceChapter ->
|
|
||||||
dbChapter.url == sourceChapter.url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return if there's nothing to add, delete or change, avoiding unnecessary db transactions.
|
// Return if there's nothing to add, delete or change, avoiding unnecessary db transactions.
|
||||||
if (toAdd.isEmpty() && toDelete.isEmpty() && toChange.isEmpty()) {
|
if (toAdd.isEmpty() && toDelete.isEmpty() && toChange.isEmpty()) {
|
||||||
return Pair(emptyList(), emptyList())
|
return Pair(emptyList(), emptyList())
|
||||||
@ -105,12 +102,13 @@ fun syncChaptersWithSource(
|
|||||||
db.inTransaction {
|
db.inTransaction {
|
||||||
val deletedChapterNumbers = TreeSet<Float>()
|
val deletedChapterNumbers = TreeSet<Float>()
|
||||||
val deletedReadChapterNumbers = TreeSet<Float>()
|
val deletedReadChapterNumbers = TreeSet<Float>()
|
||||||
|
|
||||||
if (toDelete.isNotEmpty()) {
|
if (toDelete.isNotEmpty()) {
|
||||||
for (c in toDelete) {
|
for (chapter in toDelete) {
|
||||||
if (c.read) {
|
if (chapter.read) {
|
||||||
deletedReadChapterNumbers.add(c.chapter_number)
|
deletedReadChapterNumbers.add(chapter.chapter_number)
|
||||||
}
|
}
|
||||||
deletedChapterNumbers.add(c.chapter_number)
|
deletedChapterNumbers.add(chapter.chapter_number)
|
||||||
}
|
}
|
||||||
db.deleteChapters(toDelete).executeAsBlocking()
|
db.deleteChapters(toDelete).executeAsBlocking()
|
||||||
}
|
}
|
||||||
@ -121,14 +119,14 @@ fun syncChaptersWithSource(
|
|||||||
var now = Date().time
|
var now = Date().time
|
||||||
|
|
||||||
for (i in toAdd.indices.reversed()) {
|
for (i in toAdd.indices.reversed()) {
|
||||||
val c = toAdd[i]
|
val chapter = toAdd[i]
|
||||||
c.date_fetch = now++
|
chapter.date_fetch = now++
|
||||||
// Try to mark already read chapters as read when the source deletes them
|
// Try to mark already read chapters as read when the source deletes them
|
||||||
if (c.isRecognizedNumber && c.chapter_number in deletedReadChapterNumbers) {
|
if (chapter.isRecognizedNumber && chapter.chapter_number in deletedReadChapterNumbers) {
|
||||||
c.read = true
|
chapter.read = true
|
||||||
}
|
}
|
||||||
if (c.isRecognizedNumber && c.chapter_number in deletedChapterNumbers) {
|
if (chapter.isRecognizedNumber && chapter.chapter_number in deletedChapterNumbers) {
|
||||||
readded.add(c)
|
readded.add(chapter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val chapters = db.insertChapters(toAdd).executeAsBlocking()
|
val chapters = db.insertChapters(toAdd).executeAsBlocking()
|
||||||
|
Loading…
Reference in New Issue
Block a user