Browse Source

server: Reuse the paginated query on the BlockPostgresDAO

The getFirstBlock and getLatestBlock methods use the paginated
query to get the results.
prometheus-integration
Alexis Hernandez 6 years ago
parent
commit
a8fb693018
  1. 26
      server/app/com/xsn/explorer/data/anorm/dao/BlockPostgresDAO.scala

26
server/app/com/xsn/explorer/data/anorm/dao/BlockPostgresDAO.scala

@ -4,7 +4,7 @@ import java.sql.Connection
import javax.inject.Inject
import anorm._
import com.alexitc.playsonify.models.{Count, FieldOrdering, PaginatedQuery}
import com.alexitc.playsonify.models._
import com.xsn.explorer.data.anorm.interpreters.FieldOrderingSQLInterpreter
import com.xsn.explorer.data.anorm.parsers.BlockParsers._
import com.xsn.explorer.models.fields.BlockField
@ -138,26 +138,14 @@ class BlockPostgresDAO @Inject() (fieldOrderingSQLInterpreter: FieldOrderingSQLI
}
def getLatestBlock(implicit conn: Connection): Option[Block] = {
SQL(
"""
|SELECT blockhash, previous_blockhash, next_blockhash, tpos_contract, merkle_root, size,
| height, version, time, median_time, nonce, bits, chainwork, difficulty
|FROM blocks
|ORDER BY height DESC
|LIMIT 1
""".stripMargin
).as(parseBlock.singleOpt).flatten
val query = PaginatedQuery(Offset(0), Limit(1))
val ordering = FieldOrdering(BlockField.Height, OrderingCondition.DescendingOrder)
getBy(query, ordering).headOption
}
def getFirstBlock(implicit conn: Connection): Option[Block] = {
SQL(
"""
|SELECT blockhash, previous_blockhash, next_blockhash, tpos_contract, merkle_root, size,
| height, version, time, median_time, nonce, bits, chainwork, difficulty
|FROM blocks
|ORDER BY height
|LIMIT 1
""".stripMargin
).as(parseBlock.singleOpt).flatten
val query = PaginatedQuery(Offset(0), Limit(1))
val ordering = FieldOrdering(BlockField.Height, OrderingCondition.AscendingOrder)
getBy(query, ordering).headOption
}
}

Loading…
Cancel
Save