Fix recursive sync

pull/392/head v5.2.3
Koitharu 3 years ago
parent fc8a5ccd9f
commit 009eb9fe44
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -43,10 +43,12 @@ class SyncController @Inject constructor(
private val defaultGcPeriod = TimeUnit.DAYS.toMillis(2) // gc period if sync disabled
override fun onInvalidated(tables: Set<String>) {
requestSync(
favourites = TABLE_FAVOURITES in tables || TABLE_FAVOURITE_CATEGORIES in tables,
history = TABLE_HISTORY in tables,
)
val favourites = (TABLE_FAVOURITES in tables || TABLE_FAVOURITE_CATEGORIES in tables)
&& !isSyncActiveOrPending(authorityFavourites)
val history = TABLE_HISTORY in tables && !isSyncActiveOrPending(authorityHistory)
if (favourites || history) {
requestSync(favourites, history)
}
}
fun isEnabled(account: Account): Boolean {
@ -126,6 +128,11 @@ class SyncController @Inject constructor(
}
}
private fun isSyncActiveOrPending(authority: String): Boolean {
val account = peekAccount() ?: return false
return ContentResolver.isSyncActive(account, authority) || ContentResolver.isSyncPending(account, authority)
}
companion object {
@JvmStatic

Loading…
Cancel
Save