Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

ORM: Add "foreign" key index #23

Open
alpe opened this issue Feb 21, 2020 · 0 comments
Open

ORM: Add "foreign" key index #23

alpe opened this issue Feb 21, 2020 · 0 comments

Comments

@alpe
Copy link
Collaborator

alpe commented Feb 21, 2020

TlDr;: I would like to replace the following 2 Gets on tales by an index.

func (k Keeper) GetGroupByGroupAccount(ctx sdk.Context, address sdk.AccAddress) (GroupMetadata, error) {
	var obj GroupAccountMetadataBase
	if err := k.groupAccountTable.GetOne(ctx, address.Bytes(), &obj); err != nil {
		return GroupMetadata{}, errors.Wrap(err, "load group account")
	}
	return k.GetGroup(ctx, obj.Group)
}

Scenario:
I have Groups and GroupAccounts.

message GroupAccount {
    bytes address = 1 ;
    uint64 group = 2 ;
}

When I create a new proposal we refer to a GroupAccount in the payload. To store the group version with the proposal, I would need to load the group via reference from GroupAccount.
Instead of the 2 steps to load GroupAccount by address and then load Group by GroupAccount.Group we could introduce a new index type that points to the Group entity from an GroupAccount.

All our current indexes are work with the RowGetter and type of the table builder where they are registered. For this foreign key index we would need the Group RowGetter and type but register on the GroupAccounts builder with and raw index key <GroupAccount.Address><Group.RowID>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant