Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log last sync time per collection service and URL #702

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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