Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address_transactions: order and retrieve by date (desc) #12

Open
behas opened this issue May 25, 2022 · 2 comments
Open

address_transactions: order and retrieve by date (desc) #12

behas opened this issue May 25, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@behas
Copy link
Member

behas commented May 25, 2022

Currently, address_transactions is ordered by address id. However, on the UI it would be desirable to see the latest transactions first and, if the number of transactions is large, to somehow retrieve them by date (can also be by month, year, whatever).

@behas behas added the enhancement New feature or request label May 25, 2022
@soad003
Copy link
Member

soad003 commented Nov 25, 2022

Had a look at the problem I think both of the things can be achived by restructuring how we query the table.

In e.g. the REST interface we often query the table like this:

select * from  address_transactions where address_id_group=264 and address_id=2647117;

Which results in random order. The tables clustering order is defined as follows:

...
    PRIMARY KEY (address_id_group, address_id, is_outgoing, tx_id)
) WITH CLUSTERING ORDER BY (address_id DESC, is_outgoing DESC, tx_id DESC)

Tx_id desc gives us temporal order but only if we query the right way (background), only if is_outgoing included in the filter we get ordered results (desc by tx_id).

select * from  address_transactions where address_id_group=264 and address_id=2647117 and is_outgoing=true;
select * from  address_transactions where address_id_group=264 and address_id=2647117 and is_outgoing=false;

So to receive ordered results we need to split the queries into two and add some logic in the client (REST etc.) to combine the result-sets (merge).

By including is_outgoing in the where clause we can also support range queries and switching up the order e.g.

select * from  address_transactions 
where address_id_group=264 and 
             address_id=2647117 and 
             is_outgoing=true and 
             tx_id > 1000
             order by tx_id ASC;

Using some additional lookups this could be even done by block number or date:

  • Get the block number for the start timestamp (raw block)
  • Get the first tx_id in that block (raw block_transactions)
  • Get the block number for the end timestamp (raw block)
  • Get the last tx_id in that block (raw block_transactions)

Getting the blocknumber by date is currently not efficient but could be solved by a materialized view or binary search.

@soad003
Copy link
Member

soad003 commented Apr 24, 2023

@myrho this is already implemented even in the rest interface right?

@soad003 soad003 transferred this issue from graphsense/graphsense-transformation Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants