|
|
|
@ -32,13 +32,14 @@ import coil.request.ImageRequest
|
|
|
|
import dagger.Reusable
|
|
|
|
import dagger.Reusable
|
|
|
|
import dagger.assisted.Assisted
|
|
|
|
import dagger.assisted.Assisted
|
|
|
|
import dagger.assisted.AssistedInject
|
|
|
|
import dagger.assisted.AssistedInject
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
|
|
|
|
import kotlinx.coroutines.NonCancellable
|
|
|
|
import kotlinx.coroutines.NonCancellable
|
|
|
|
import kotlinx.coroutines.async
|
|
|
|
import kotlinx.coroutines.async
|
|
|
|
import kotlinx.coroutines.awaitAll
|
|
|
|
import kotlinx.coroutines.awaitAll
|
|
|
|
import kotlinx.coroutines.flow.Flow
|
|
|
|
import kotlinx.coroutines.flow.Flow
|
|
|
|
import kotlinx.coroutines.flow.map
|
|
|
|
import kotlinx.coroutines.flow.map
|
|
|
|
import kotlinx.coroutines.supervisorScope
|
|
|
|
import kotlinx.coroutines.supervisorScope
|
|
|
|
|
|
|
|
import kotlinx.coroutines.sync.Semaphore
|
|
|
|
|
|
|
|
import kotlinx.coroutines.sync.withPermit
|
|
|
|
import kotlinx.coroutines.withContext
|
|
|
|
import kotlinx.coroutines.withContext
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.R
|
|
|
|
import org.koitharu.kotatsu.core.logs.FileLogger
|
|
|
|
import org.koitharu.kotatsu.core.logs.FileLogger
|
|
|
|
@ -119,23 +120,25 @@ class TrackWorker @AssistedInject constructor(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private suspend fun checkUpdatesAsync(tracks: List<TrackingItem>): List<MangaUpdates?> {
|
|
|
|
private suspend fun checkUpdatesAsync(tracks: List<TrackingItem>): List<MangaUpdates?> {
|
|
|
|
val dispatcher = Dispatchers.Default.limitedParallelism(MAX_PARALLELISM)
|
|
|
|
val semaphore = Semaphore(MAX_PARALLELISM)
|
|
|
|
return supervisorScope {
|
|
|
|
return supervisorScope {
|
|
|
|
tracks.map { (track, channelId) ->
|
|
|
|
tracks.map { (track, channelId) ->
|
|
|
|
async(dispatcher) {
|
|
|
|
async {
|
|
|
|
runCatchingCancellable {
|
|
|
|
semaphore.withPermit {
|
|
|
|
tracker.fetchUpdates(track, commit = true)
|
|
|
|
runCatchingCancellable {
|
|
|
|
}.onFailure {
|
|
|
|
tracker.fetchUpdates(track, commit = true)
|
|
|
|
logger.log("checkUpdatesAsync", it)
|
|
|
|
}.onFailure {
|
|
|
|
}.onSuccess { updates ->
|
|
|
|
logger.log("checkUpdatesAsync", it)
|
|
|
|
if (updates.isValid && updates.isNotEmpty()) {
|
|
|
|
}.onSuccess { updates ->
|
|
|
|
showNotification(
|
|
|
|
if (updates.isValid && updates.isNotEmpty()) {
|
|
|
|
manga = updates.manga,
|
|
|
|
showNotification(
|
|
|
|
channelId = channelId,
|
|
|
|
manga = updates.manga,
|
|
|
|
newChapters = updates.newChapters,
|
|
|
|
channelId = channelId,
|
|
|
|
)
|
|
|
|
newChapters = updates.newChapters,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}.getOrNull()
|
|
|
|
}
|
|
|
|
|
|
|
|
}.getOrNull()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.awaitAll()
|
|
|
|
}.awaitAll()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -299,7 +302,7 @@ class TrackWorker @AssistedInject constructor(
|
|
|
|
const val WORKER_NOTIFICATION_ID = 35
|
|
|
|
const val WORKER_NOTIFICATION_ID = 35
|
|
|
|
const val TAG = "tracking"
|
|
|
|
const val TAG = "tracking"
|
|
|
|
const val TAG_ONESHOT = "tracking_oneshot"
|
|
|
|
const val TAG_ONESHOT = "tracking_oneshot"
|
|
|
|
const val MAX_PARALLELISM = 4
|
|
|
|
const val MAX_PARALLELISM = 3
|
|
|
|
const val DATA_KEY_SUCCESS = "success"
|
|
|
|
const val DATA_KEY_SUCCESS = "success"
|
|
|
|
const val DATA_KEY_FAILED = "failed"
|
|
|
|
const val DATA_KEY_FAILED = "failed"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|