From f05ef89fbc1d6d2253c89302f9c45f745867679f Mon Sep 17 00:00:00 2001 From: Carlton N Hanna Date: Mon, 30 Oct 2023 09:51:52 -0600 Subject: [PATCH] tmp delete then insert, removing after testing --- .../io/provenance/explorer/domain/entities/ExplorerCache.kt | 5 +++++ .../io/provenance/explorer/service/async/AsyncService.kt | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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 b267bfd2..44223fb4 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 @@ -2,6 +2,7 @@ package io.provenance.explorer.domain.entities import io.provenance.explorer.OBJECT_MAPPER import io.provenance.explorer.domain.core.sql.jsonb +import io.provenance.explorer.domain.extensions.startOfDay import io.provenance.explorer.model.ChainAum import io.provenance.explorer.model.ChainMarketRate import io.provenance.explorer.model.CmcHistoricalQuote @@ -281,6 +282,10 @@ 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 ba85b1bf..b1d68b7b 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 @@ -307,6 +307,8 @@ class AsyncService( .map { it to emptyList() }.toMap().toMutableMap() var prevPrice = TokenHistoricalDailyRecord.lastKnownPriceForDate(startDate) + TokenHistoricalDailyRecord + baseMap.putAll( dlobRes.buy .filter { DateTime(it.trade_timestamp * 1000).startOfDay() != today } @@ -339,7 +341,9 @@ class AsyncService( ) ) ).also { prevPrice = close } - TokenHistoricalDailyRecord.save(record.time_open.startOfDay(), record) + 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}") } }