diff --git a/service/src/main/kotlin/io/provenance/explorer/domain/entities/ExplorerCache.kt b/service/src/main/kotlin/io/provenance/explorer/domain/entities/ExplorerCache.kt index 44223fb4..d9fa1060 100644 --- a/service/src/main/kotlin/io/provenance/explorer/domain/entities/ExplorerCache.kt +++ b/service/src/main/kotlin/io/provenance/explorer/domain/entities/ExplorerCache.kt @@ -282,10 +282,6 @@ class TokenHistoricalDailyRecord(id: EntityID) : Entity(id) .limit(1) .firstOrNull() } - - fun deleteByDate(date: DateTime) = transaction { - TokenHistoricalDailyTable.deleteWhere { TokenHistoricalDailyTable.timestamp eq date.startOfDay() } - } } var timestamp by TokenHistoricalDailyTable.timestamp diff --git a/service/src/main/kotlin/io/provenance/explorer/service/async/AsyncService.kt b/service/src/main/kotlin/io/provenance/explorer/service/async/AsyncService.kt index b1d68b7b..2b043df3 100644 --- a/service/src/main/kotlin/io/provenance/explorer/service/async/AsyncService.kt +++ b/service/src/main/kotlin/io/provenance/explorer/service/async/AsyncService.kt @@ -293,12 +293,11 @@ class AsyncService( @Scheduled(cron = "0 0 1 * * ?") // Every day at 1 am fun updateTokenHistorical() { val today = DateTime.now().startOfDay() -// var startDate = today.minusMonths(1) -// val latest = TokenHistoricalDailyRecord.getLatestDateEntry() -// if (latest != null) { -// startDate = latest.timestamp.minusDays(1).startOfDay() -// } - val startDate = DateTime(2023, 8, 4, 0, 0, 0).startOfDay() + var startDate = today.minusMonths(1) + val latest = TokenHistoricalDailyRecord.getLatestDateEntry() + if (latest != null) { + startDate = latest.timestamp.minusDays(1).startOfDay() + } val dlobRes = tokenService.getHistoricalFromDlob(startDate) ?: return logger.info("Updating token historical data starting from $startDate with ${dlobRes.buy.size} buy records for roll-up.") @@ -341,9 +340,7 @@ class AsyncService( ) ) ).also { prevPrice = close } - TokenHistoricalDailyRecord.deleteByDate(record.time_open.startOfDay()) - val id = TokenHistoricalDailyRecord.save(record.time_open.startOfDay(), record) - logger.info("saving record ${record.time_open.startOfDay()} $record insert count ${id.insertedCount}") + TokenHistoricalDailyRecord.save(record.time_open.startOfDay(), record) } }