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

Improve account_balance indexing #529

Closed
theoreticalbts opened this issue Jan 21, 2016 · 2 comments
Closed

Improve account_balance indexing #529

theoreticalbts opened this issue Jan 21, 2016 · 2 comments
Assignees
Milestone

Comments

@theoreticalbts
Copy link
Contributor

The account_balance indexing is currently defined as:

  typedef multi_index_container<                                                                                                                                                                                                         
     account_balance_object,                                                                                                                                                                                                             
     indexed_by<                                                                                                                                                                                                                         
        ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,                                                                                                                                                     
        ordered_unique< tag<by_balance>, composite_key<                                                                                                                                                                                  
                                            account_balance_object,                                                                                                                                                                      
                                            member<account_balance_object, account_id_type, &account_balance_object::owner>,                                                                                                             
                                            member<account_balance_object, asset_id_type, &account_balance_object::asset_type> >                                                                                                         
                        >,                                                                                                                                                                                                               
        ordered_non_unique< tag<by_account>, member<account_balance_object, account_id_type, &account_balance_object::owner> >,                                                                                                          
        ordered_non_unique< tag<by_asset>, member<account_balance_object, asset_id_type, &account_balance_object::asset_type> >                                                                                                          
        >                                                                                                                                                                                                                                
     > account_balance_object_multi_index_type;

The by_account index is redundant, as the by_balance index (which could be better named by_account_asset) can answer any query the by_account index can.

In addition, an index by (asset_type, balance) is required to support top_n authority. Again, the by_asset functionality can be assumed by this new index.

So the solution is:

  • Rename by_balance to by_account_asset
  • Remove by_account and rewrite logic to use by_account_asset instead
  • Expand by_asset to composite key on (asset_type, balance)

The equal_range() of boost::multi_index_container will be useful for the new logic.

@theoreticalbts
Copy link
Contributor Author

We need to have composite_key_compare like this:

        composite_key_compare<
           std::less< asset_id_type >,
           std::greater< share_type >,
           std::less< account_id_type >
        >

so that the ordering is increasing asset ID, decreasing balance within an asset ID, and increasing account ID. So effectively the "rich list" for each asset, with ID as tiebreaker (a lower ID is ranked above a higher ID with equal balance).

@theoreticalbts
Copy link
Contributor Author

That was easier than I expected. Apparently by_asset wasn't actually being used by anything!

@theoreticalbts theoreticalbts self-assigned this Jan 21, 2016
@theoreticalbts theoreticalbts added this to the next2 milestone Jan 21, 2016
pmconrad pushed a commit to pmconrad/graphene that referenced this issue Aug 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant