Skip to content

Commit

Permalink
server: Simplify the light wallet transactions retrieval query
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexITC committed Dec 28, 2018
1 parent 38ab0e1 commit 2db4f9f
Showing 1 changed file with 8 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,30 +115,18 @@ class TransactionPostgresDAO @Inject() (fieldOrderingSQLInterpreter: FieldOrderi
limit: Limit)(
implicit conn: Connection): List[Transaction] = {

/**
* TODO: Update query to:
WITH CTE AS (
SELECT time AS lastSeenTime
FROM transactions
WHERE txid = {lastSeenTxid}
)
SELECT t.txid, t.blockhash, t.time, t.size
FROM CTE CROSS JOIN transactions t
JOIN address_transaction_details USING (txid)
WHERE address = {address} AND
(t.time < lastSeenTime OR (t.time = lastSeenTime AND t.txid > {lastSeenTxid}))
ORDER BY time DESC
LIMIT {limit}
*/
SQL(
"""
|WITH CTE AS (
| SELECT time AS lastSeenTime
| FROM transactions
| WHERE txid = {lastSeenTxid}
|)
|SELECT t.txid, t.blockhash, t.time, t.size
|FROM transactions t
| JOIN address_transaction_details USING (txid)
|FROM CTE CROSS JOIN transactions t
| JOIN address_transaction_details USING (txid)
|WHERE address = {address} AND
| (t.time < (SELECT time AS lastSeenTime FROM transactions WHERE txid = {lastSeenTxid}) OR
| (t.time = (SELECT time AS lastSeenTime FROM transactions WHERE txid = {lastSeenTxid}) AND
| t.txid > {lastSeenTxid}))
| (t.time < lastSeenTime OR (t.time = lastSeenTime AND t.txid > {lastSeenTxid}))
|ORDER BY time DESC
|LIMIT {limit}
""".stripMargin
Expand Down

0 comments on commit 2db4f9f

Please sign in to comment.