Skip to content

Commit

Permalink
Remove running_count and total_count columns from the `missed_blo…
Browse files Browse the repository at this point in the history
…cks` table (#564)

* remove column properties from table identity

* remove unused query methods

* add flyway drop column script

* add change log entry

* fix lint
  • Loading branch information
nullpointer0x00 authored Oct 28, 2024
1 parent e696de8 commit 061f488
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Remove spotlight from caching to the database [#532](https://github.com/provenance-io/explorer-service/issues/532)
* Update keep alive times for flow api grpc calls [#558](https://github.com/provenance-io/explorer-service/pull/558)
* Updates to asset pricing table will set data column to null [#562](https://github.com/provenance-io/explorer-service/pull/562)
* Remove `running_count` and `total_count` columns from the `missed_blocks` table [#549](https://github.com/provenance-io/explorer-service/issues/549)

### Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT 'Remove running_count and total_count columns from the missed_blocks table' AS comment;

DROP INDEX IF EXISTS missed_blocks_running_count_idx;

ALTER TABLE missed_blocks
DROP COLUMN IF EXISTS running_count,
DROP COLUMN IF EXISTS total_count;
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.insertIgnore
import org.jetbrains.exposed.sql.jodatime.DateColumnType
import org.jetbrains.exposed.sql.jodatime.datetime
import org.jetbrains.exposed.sql.leftJoin
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.sum
Expand Down Expand Up @@ -205,24 +204,6 @@ class BlockProposerRecord(id: EntityID<Int>) : IntEntity(id) {
it.getBigDecimal("avg_block_creation_time")
}.firstOrNull() ?: BigDecimal.ZERO
}

fun findMissingRecords(min: Int, max: Int, limit: Int) = transaction {
BlockCacheTable
.leftJoin(BlockProposerTable, { BlockCacheTable.height }, { BlockProposerTable.blockHeight })
.slice(BlockCacheTable.columns)
.select { (BlockProposerTable.blockHeight.isNull()) and (BlockCacheTable.height.between(min, max)) }
.orderBy(BlockCacheTable.height, SortOrder.ASC)
.limit(limit)
.let { BlockCacheRecord.wrapRows(it).toSet() }
}

fun getRecordsForProposer(address: String, limit: Int) = transaction {
BlockProposerRecord.find {
(BlockProposerTable.proposerOperatorAddress eq address)
}.orderBy(Pair(BlockProposerTable.blockHeight, SortOrder.DESC))
.limit(limit)
.toList()
}
}

var blockHeight by BlockProposerTable.blockHeight
Expand All @@ -233,8 +214,6 @@ class BlockProposerRecord(id: EntityID<Int>) : IntEntity(id) {
object MissedBlocksTable : IntIdTable(name = "missed_blocks") {
val blockHeight = integer("block_height")
val valConsAddr = varchar("val_cons_address", 128)
val runningCount = integer("running_count")
val totalCount = integer("total_count")
}

class MissedBlocksRecord(id: EntityID<Int>) : IntEntity(id) {
Expand Down Expand Up @@ -271,17 +250,12 @@ class MissedBlocksRecord(id: EntityID<Int>) : IntEntity(id) {
MissedBlocksTable.insertIgnore {
it[this.blockHeight] = height
it[this.valConsAddr] = valconsAddr
// TODO: remove these column from database See: https://github.com/provenance-io/explorer-service/issues/549
it[this.runningCount] = -1
it[this.totalCount] = -1
}
}
}

var blockHeight by MissedBlocksTable.blockHeight
var valConsAddr by MissedBlocksTable.valConsAddr
var runningCount by MissedBlocksTable.runningCount
var totalCount by MissedBlocksTable.totalCount
}

object BlockCacheHourlyTxCountsTable : IdTable<DateTime>(name = "block_cache_hourly_tx_counts") {
Expand Down

0 comments on commit 061f488

Please sign in to comment.