From 235b03bcbaccd538c4ff014c48a241a76863927e Mon Sep 17 00:00:00 2001 From: KaiserBh Date: Mon, 20 Nov 2023 06:18:57 +1100 Subject: [PATCH] refactor: remove the random delay! Chances of conflict is pretty low since it's saved in ms so can just remove it. Signed-off-by: KaiserBh --- .../java/eu/kanade/tachiyomi/data/sync/SyncDataJob.kt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncDataJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncDataJob.kt index a45753d08..40abcc802 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncDataJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncDataJob.kt @@ -65,12 +65,8 @@ class SyncDataJob(private val context: Context, workerParams: WorkerParameters) fun setupTask(context: Context, prefInterval: Int? = null) { val syncPreferences = Injekt.get() val interval = prefInterval ?: syncPreferences.syncInterval().get() + if (interval > 0) { - // Generate a random delay in minutes (e.g., between 0 and 15 minutes) to avoid conflicts. - val randomDelay = Random.nextInt(0, 16) - - val randomDelayMillis = TimeUnit.MINUTES.toMillis(randomDelay.toLong()) - val request = PeriodicWorkRequestBuilder( interval.toLong(), TimeUnit.MINUTES, @@ -78,7 +74,7 @@ class SyncDataJob(private val context: Context, workerParams: WorkerParameters) TimeUnit.MINUTES, ) .addTag(TAG_AUTO) - .setInitialDelay(randomDelayMillis, TimeUnit.MILLISECONDS) + // No initial delay is needed, remove the randomDelayMillis .build() context.workManager.enqueueUniquePeriodicWork(TAG_AUTO, ExistingPeriodicWorkPolicy.UPDATE, request)