Skip to content

Commit

Permalink
Show more detailed sync reports
Browse files Browse the repository at this point in the history
  • Loading branch information
bubelov committed Apr 30, 2024
1 parent 2cea46f commit ecc0148
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 27 deletions.
6 changes: 3 additions & 3 deletions app/src/main/kotlin/event/EventsRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class EventsRepo(
suspend fun sync(): SyncReport {
val startedAt = ZonedDateTime.now(ZoneOffset.UTC)
val newEvents = mutableListOf<Event>()
val updatedEvents = mutableListOf<Event>()
var updatedEvents = 0L
val maxUpdatedAtBeforeSync = queries.selectMaxUpdatedAt()

while (true) {
Expand All @@ -30,7 +30,7 @@ class EventsRepo(
) {
newEvents += it
} else {
updatedEvents += it
updatedEvents += 1
}
}

Expand All @@ -51,7 +51,7 @@ class EventsRepo(
data class SyncReport(
val duration: Duration,
val newEvents: List<Event>,
val updatedEvents: List<Event>,
val updatedEvents: Long,
)

companion object {
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/kotlin/reports/ReportsRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class ReportsRepo(

suspend fun sync(): SyncReport {
val startedAt = ZonedDateTime.now(ZoneOffset.UTC)
val newReports = mutableListOf<Report>()
val updatedReports = mutableListOf<Report>()
var newReports = 0L
var updatedReports = 0L
val maxUpdatedAtBeforeSync = queries.selectMaxUpdatedAt()

while (true) {
Expand All @@ -47,9 +47,9 @@ class ReportsRepo(
if (maxUpdatedAtBeforeSync == null
|| it.createdAt.isAfter(maxUpdatedAtBeforeSync)
) {
newReports += it
newReports += 1
} else {
updatedReports += it
updatedReports += 1
}
}

Expand All @@ -69,8 +69,8 @@ class ReportsRepo(

data class SyncReport(
val duration: Duration,
val newReports: List<Report>,
val updatedReports: List<Report>,
val newReports: Long,
val updatedReports: Long,
)

companion object {
Expand Down
24 changes: 10 additions & 14 deletions app/src/main/kotlin/sync/Sync.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import area.AreasRepo
import conf.ConfRepo
import reports.ReportsRepo
import element.ElementsRepo
import event.Event
import event.EventsRepo
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
Expand All @@ -13,7 +12,6 @@ import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withContext
import reports.Report
import time.now
import user.UsersRepo
import java.time.ZoneOffset
Expand Down Expand Up @@ -65,12 +63,11 @@ class Sync(
val fullReport = SyncReport(
startedAt = startedAt,
finishedAt = ZonedDateTime.now(ZoneOffset.UTC),
newElements = elementsReport.await().newElements,
updatedElements = elementsReport.await().updatedElements,
newReports = reportsReport.await().newReports,
updatedReports = reportsReport.await().updatedReports,
newEvents = eventsReport.await().newEvents,
updatedEvents = eventsReport.await().updatedEvents,
elementsReport = elementsReport.await(),
reportsReport = reportsReport.await(),
eventsReport = eventsReport.await(),
areasReport = areasReport.await(),
usersReport = usersReport.await(),
)

syncNotificationController.showPostSyncNotifications(
Expand All @@ -90,10 +87,9 @@ class Sync(
data class SyncReport(
val startedAt: ZonedDateTime,
val finishedAt: ZonedDateTime,
val newElements: Long,
val updatedElements: Long,
val newReports: List<Report>,
val updatedReports: List<Report>,
val newEvents: List<Event>,
val updatedEvents: List<Event>,
val elementsReport: ElementsRepo.SyncReport,
val reportsReport: ReportsRepo.SyncReport,
val eventsReport: EventsRepo.SyncReport,
val areasReport: AreasRepo.SyncReport,
val usersReport: UsersRepo.SyncReport,
)
10 changes: 6 additions & 4 deletions app/src/main/kotlin/sync/SyncNotificationController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ class SyncNotificationController(
.bigText(
"""
|Time: $syncTimeMillis ms
|Elements: ${report.newElements} new, ${report.updatedElements} updated
|Events: ${report.newEvents.size} new, ${report.updatedEvents.size} updated
|Reports: ${report.newReports.size} new, ${report.updatedReports.size} updated
|Elements: ${report.elementsReport.newElements} new, ${report.elementsReport.updatedElements} updated in ${report.elementsReport.duration.toMillis()} ms
|Events: ${report.eventsReport.newEvents.size} new, ${report.eventsReport.updatedEvents} updated in ${report.eventsReport.duration.toMillis()} ms
|Reports: ${report.reportsReport.newReports} new, ${report.reportsReport.updatedReports} updated in ${report.reportsReport.duration.toMillis()} ms
|Areas: ${report.areasReport.createdOrUpdatedAreas} in ${report.areasReport.timeMillis}
|Users: ${report.usersReport.createdOrUpdatedUsers} in ${report.usersReport.timeMillis}
""".trimMargin()
)
)
Expand All @@ -72,7 +74,7 @@ class SyncNotificationController(

createNewMerchantsNotificationChannel(context)

report.newEvents.forEach { newEvent ->
report.eventsReport.newEvents.forEach { newEvent ->
if (newEvent.type == "create") {
val element =
runBlocking { elementsRepo.selectByOsmId(newEvent.elementId) } ?: return
Expand Down

0 comments on commit ecc0148

Please sign in to comment.