Skip to content

Commit ded4250

Browse files
committed
update read stats asynchronously as well
1 parent dc3538d commit ded4250

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

src/main/kotlin/ch/derlin/bbdata/common/stats/StatsLogic.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,20 @@ data class Stats(
2828
)
2929

3030
interface StatsLogic {
31-
fun incrementReadCounter(objectId: Long)
31+
3232
fun getStats(objectId: Long): Stats
3333
fun updateStats(v: NewValue)
34+
fun incrementReadCounter(objectId: Long)
35+
fun updateAllStats(vs: List<NewValue>) {
36+
vs.forEach { updateStats(it) }
37+
}
38+
39+
@Async
40+
fun incrementReadCounterAsync(objectId: Long) = incrementReadCounter(objectId)
3441

3542
@Async
3643
fun updateAllStatsAsync(vs: List<NewValue>) = updateAllStats(vs)
3744

38-
fun updateAllStats(vs: List<NewValue>) {
39-
vs.forEach { updateStats(it) }
40-
}
4145

4246
}
4347

src/main/kotlin/ch/derlin/bbdata/output/api/values/ValuesController.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ class ValuesController(
5555
checkObject(userId, objectId)
5656
val to = optionalTo ?: DateTime.now()
5757
val months = CassandraUtils.monthsBetween(YearMonth(from), YearMonth(to))
58+
59+
// update stats
60+
statsLogic.incrementReadCounterAsync(objectId)
61+
5862
// stream the values
5963
cassandraObjectStreamer.stream(contentType, response, RawValue.csvHeaders,
6064
rawValueRepository.findByTimestampBetween(objectId.toInt(), months, from, to))
61-
// update stats
62-
statsLogic.incrementReadCounter(objectId)
6365

6466
}
6567

@@ -79,12 +81,13 @@ class ValuesController(
7981
// do the search
8082
val latest = rawValueRepository.findLatestValue(objectId, obj.creationdate!!, optionalBefore ?: DateTime.now())
8183

84+
// update stats
85+
statsLogic.incrementReadCounterAsync(objectId)
86+
8287
// stream the results
8388
cassandraObjectStreamer.stream(
8489
contentType, response, RawValue.csvHeaders,
8590
if (latest == null) listOf() else listOf(latest))
86-
// update stats
87-
statsLogic.incrementReadCounter(objectId)
8891
}
8992

9093
@Protected
@@ -107,12 +110,14 @@ class ValuesController(
107110
val minutes = granularity.minutes
108111
val to = optionalTo ?: DateTime.now()
109112
val months = CassandraUtils.monthsBetween(YearMonth(from), YearMonth(to))
113+
114+
// update stats
115+
statsLogic.incrementReadCounterAsync(objectId)
116+
110117
// stream the results
111118
cassandraObjectStreamer.stream(
112119
contentType, response, Aggregation.csvHeaders,
113120
aggregationsRepository.findByTimestampBetween(minutes, objectId.toInt(), months, from, to))
114-
// update stats
115-
statsLogic.incrementReadCounter(objectId)
116121
}
117122

118123

0 commit comments

Comments
 (0)