feat: Enhanced SyncYomi with Robust Locking Mechanism

- Introduced `LockFile` data class to manage sync status and ownership.
- Enumerated `SyncStatus` to clearly indicate the stage of synchronization: Pending, Syncing, or Success.
- Implemented a new `beforeSync` method utilizing `OkHttpClient` for secure HTTP calls to manage the lock file.
- Added JSON serialization for lock file management and status updates.
- Implemented exponential backoff strategy to handle concurrent sync attempts and reduce race conditions.
- Added comprehensive logging for debugging and monitoring sync processes.

This update enhances the reliability and concurrency handling of SyncYomi's synchronization process, ensuring users experience seamless and efficient data syncing in a self-hosted environment.

Signed-off-by: KaiserBh <kaiserbh@proton.me>
This commit is contained in:
KaiserBh
2024-01-07 09:50:30 +11:00
parent 39d5714a1b
commit eb5b1610d0
2 changed files with 108 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package tachiyomi.domain.sync
import tachiyomi.core.preference.Preference
import tachiyomi.core.preference.PreferenceStore
import java.util.UUID
class SyncPreferences(
private val preferenceStore: PreferenceStore,
@@ -22,4 +23,18 @@ class SyncPreferences(
Preference.appStateKey("google_drive_refresh_token"),
"",
)
fun uniqueDeviceID(): String {
val uniqueIDPreference = preferenceStore.getString("unique_device_id", "")
// Retrieve the current value of the preference
var uniqueID = uniqueIDPreference.get()
if (uniqueID.isBlank()) {
uniqueID = UUID.randomUUID().toString()
uniqueIDPreference.set(uniqueID)
}
return uniqueID
}
}