Skip to content

Commit

Permalink
Log last sync time per collection service and URL (#702)
Browse files Browse the repository at this point in the history
* Log last sync time per collection service and URL

* Remove unused deprecated method

* Include tasks and other services as caldav type
  • Loading branch information
sunkup committed May 14, 2024
1 parent a246046 commit b4e58ee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
4 changes: 0 additions & 4 deletions app/src/main/kotlin/at/bitfire/davdroid/db/CollectionDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
30 changes: 22 additions & 8 deletions app/src/main/kotlin/at/bitfire/davdroid/syncadapter/SyncManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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].
Expand Down

0 comments on commit b4e58ee

Please sign in to comment.