Skip to content

Commit

Permalink
fixes #185 (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-claw authored Apr 20, 2024
1 parent 564033e commit 0012e3b
Showing 1 changed file with 19 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package me.vripper.tasks

import kotlinx.coroutines.runBlocking
import me.vripper.entities.LogEntryEntity
import me.vripper.entities.LogEntryEntity.Status.ERROR
import me.vripper.entities.ThreadEntity
import me.vripper.model.Settings
import me.vripper.model.ThreadPostId
import me.vripper.parser.ThreadItem
import me.vripper.services.AppEndpointService
import me.vripper.services.DataTransaction
import me.vripper.services.SettingsService
import me.vripper.services.ThreadCacheService
Expand All @@ -23,7 +20,6 @@ class ThreadLookupRunnable(private val threadId: Long, private val settings: Set
private val dataTransaction by inject<DataTransaction>()
private val settingsService by inject<SettingsService>()
private val threadCacheService by inject<ThreadCacheService>()
private val appEndpointService by inject<AppEndpointService>()
private val link: String = "${settingsService.settings.viperSettings.host}/threads/$threadId"

override fun run() {
Expand Down Expand Up @@ -51,18 +47,26 @@ class ThreadLookupRunnable(private val threadId: Long, private val settings: Set
)
return
}
try {
dataTransaction.save(
ThreadEntity(
title = threadLookupResult.title,
link = link,
threadId = threadId,
total = threadLookupResult.postItemList.size

if (threadLookupResult.postItemList.size <= settings.downloadSettings.autoQueueThreshold) {
CompletableFuture.runAsync(AddPostRunnable(threadLookupResult.postItemList.map {
ThreadPostId(
it.threadId, it.postId
)
)
autostart(threadLookupResult)
} catch (e: Exception) {
e.printStackTrace()
}), GLOBAL_EXECUTOR)
} else {
try {
dataTransaction.save(
ThreadEntity(
title = threadLookupResult.title,
link = link,
threadId = threadId,
total = threadLookupResult.postItemList.size
)
)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
} catch (e: Exception) {
Expand All @@ -80,17 +84,4 @@ class ThreadLookupRunnable(private val threadId: Long, private val settings: Set
Tasks.decrement()
}
}

private fun autostart(lookupResult: ThreadItem) {
if (lookupResult.postItemList.size <= settings.downloadSettings.autoQueueThreshold) {
runBlocking {
appEndpointService.threadRemove(listOf(lookupResult.threadId))
}
CompletableFuture.runAsync(AddPostRunnable(lookupResult.postItemList.map {
ThreadPostId(
it.threadId, it.postId
)
}), GLOBAL_EXECUTOR)
}
}
}

0 comments on commit 0012e3b

Please sign in to comment.