Log last sync time per collection service and URL (#702)

* Log last sync time per collection service and URL

* Remove unused deprecated method

* Include tasks and other services as caldav type
This commit is contained in:
Sunik Kupfer 2024-05-14 21:28:18 +02:00 committed by GitHub
parent a246046f41
commit b4e58eeb44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 12 deletions

View File

@ -50,10 +50,6 @@ interface CollectionDao {
@Query("SELECT collection.* FROM collection, homeset WHERE collection.serviceId=:serviceId AND type=:type AND homeSetId=homeset.id AND homeset.personal ORDER BY collection.displayName COLLATE NOCASE, collection.url COLLATE NOCASE")
fun pagePersonalByServiceAndType(serviceId: Long, type: String): PagingSource<Int, Collection>
@Deprecated("Use getByServiceAndUrl instead")
@Query("SELECT * FROM collection WHERE url=:url")
fun getByUrl(url: String): Collection?
@Query("SELECT * FROM collection WHERE serviceId=:serviceId AND url=:url")
fun getByServiceAndUrl(serviceId: Long, url: String): Collection?

View File

@ -38,6 +38,7 @@ import at.bitfire.dav4jvm.property.webdav.SyncToken
import at.bitfire.davdroid.InvalidAccountException
import at.bitfire.davdroid.R
import at.bitfire.davdroid.db.AppDatabase
import at.bitfire.davdroid.db.Service
import at.bitfire.davdroid.db.SyncState
import at.bitfire.davdroid.db.SyncStats
import at.bitfire.davdroid.log.Logger
@ -185,14 +186,7 @@ abstract class SyncManager<ResourceType: LocalResource<*>, out CollectionType: L
}
// log sync time
val db = EntryPointAccessors.fromApplication(context, SyncManagerEntryPoint::class.java).appDatabase()
db.runInTransaction {
db.collectionDao().getByUrl(collectionURL.toString())?.let { collection ->
db.syncStatsDao().insertOrReplace(
SyncStats(0, collection.id, authority, System.currentTimeMillis())
)
}
}
logSyncTime()
Logger.log.info("Querying server capabilities")
var remoteSyncState = queryCapabilities()
@ -332,6 +326,26 @@ abstract class SyncManager<ResourceType: LocalResource<*>, out CollectionType: L
})
}
private fun logSyncTime() {
val serviceType = when (authority) {
ContactsContract.AUTHORITY, // Contacts
context.getString(R.string.address_books_authority) -> // Address books
Service.TYPE_CARDDAV
else -> // Calendars + other (ie. tasks)
Service.TYPE_CALDAV
}
val db = EntryPointAccessors.fromApplication(context, SyncManagerEntryPoint::class.java).appDatabase()
db.runInTransaction {
val service = db.serviceDao().getByAccountAndType(account.name, serviceType)
?: return@runInTransaction
val collection = db.collectionDao().getByServiceAndUrl(service.id, collectionURL.toString())
?: return@runInTransaction
db.syncStatsDao().insertOrReplace(
SyncStats(0, collection.id, authority, System.currentTimeMillis())
)
}
}
/**
* Prepares synchronization. Sets the lateinit properties [collectionURL] and [davCollection].