kadena-io / chainweb-data

Data ingestion for Chainweb.
BSD 3-Clause "New" or "Revised" License
14 stars 8 forks source link

Simplify the handling of the recentTxs #140

Closed enobayram closed 1 year ago

enobayram commented 1 year ago

This PR removes the recentTxs tracking from the CW-D server state and always makes a DB query when recent transactions are needed.

With the current indexes that we have in place, the recent txs query is very fast to execute (see #119), so there's no need to complicate the server state for it anymore.

Note that, in addition to simplifying the codebase, this PR is also needed for the continuations search improvements mentioned here as well as for the planned work of decoupling the node listener from the HTTP API server.

enobayram commented 1 year ago

Here's the query that gets executed by the recent transactions handler:

=> EXPLAIN ANALYZE 
SELECT "t0"."chainid" AS "res0", "t0"."height" AS "res1", "t0"."block" AS "res2", "t0"."creationtime" AS "res3", "t0"."requestkey" AS "res4", "t0"."sender" AS "res5", "t0"."code" AS "res6", "t0"."continuation" AS "res7", "t0"."goodresult" AS "res8" 
FROM "transactions" AS "t0" 
ORDER BY "t0"."height" DESC 
LIMIT 20;
                                                                                QUERY PLAN                                                                                
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=0.43..24.48 rows=20 width=1127) (actual time=0.042..0.113 rows=20 loops=1)
   ->  Index Scan Backward using transactions_height_idx on transactions t0  (cost=0.43..16022668.97 rows=13324521 width=1127) (actual time=0.040..0.106 rows=20 loops=1)
 Planning Time: 0.166 ms
 Execution Time: 0.153 ms
(4 rows)

So it should be OK to perform it every time its's needed.