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

Change how chain links are stored #480

Closed
RiccardoM opened this issue Jun 11, 2021 · 4 comments · Fixed by #489
Closed

Change how chain links are stored #480

RiccardoM opened this issue Jun 11, 2021 · 4 comments · Fixed by #489
Assignees
Labels
kind/enhancement Enhance an already existing feature; no "New feature" to add x/profiles Module that allows to create and manage decentralized social profiles
Milestone

Comments

@RiccardoM
Copy link
Contributor

Overview

When working towards #472, I realized that currently chain links are stored associated with a profile inside the Profile object itself. While this is very handy when querying them, the major downside is that when storing a chain link we need to update the whole profile. Since the gas usage is based on how much data is written during a transaction, this will cause later changes to the chain links slice to be extremely costly. Suppose we have a profile with already 10 links, if we add the 11th we need to write the whole slice again so we are writing 10 objects that we should not.

Changes proposal

For the above reason, I think what we can do is change how chain links are stored by using the same method we use with other repeated data (eg: DTag requests, blocks, etc):

ChainLinkPrefix + username + chain_name + chain_address -> ChainLink

This would allow us to check the existence of a link in O(1) time as well as to query for such link in the same time.

If this is implemented, the ProfileByChainLinkQuery needs to be replaced with a UserChainLinks paginated query.

Please @dadamu @bragaz let me know what you think about this change.

@RiccardoM RiccardoM added kind/enhancement Enhance an already existing feature; no "New feature" to add x/profiles Module that allows to create and manage decentralized social profiles labels Jun 11, 2021
@dadamu
Copy link
Contributor

dadamu commented Jun 11, 2021

I highly agree with it. In my opinion, chain links should be isolated to the profile. It brings more flexibility to operate with chain link. And we can avoid the updating all chain links for profile when creating a new link as you said.

@dadamu dadamu self-assigned this Jun 11, 2021
@leobragaz
Copy link
Contributor

As we did for subspaces with admins and registered users this is the best way to go for this too. 💪

@RiccardoM
Copy link
Contributor Author

@dadamu Are you currently working on this? If not, I might be able to pick it up in the next days before starting to review all the tests

@dadamu
Copy link
Contributor

dadamu commented Jun 15, 2021

@RiccardoM Yes, I am working on it.

@RiccardoM RiccardoM added this to the v0.17.0 milestone Jun 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Enhance an already existing feature; no "New feature" to add x/profiles Module that allows to create and manage decentralized social profiles
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants