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

feat: add Metadata.findDataByOwner #68

Merged
merged 1 commit into from
Nov 23, 2021
Merged

feat: add Metadata.findDataByOwner #68

merged 1 commit into from
Nov 23, 2021

Conversation

solberenson
Copy link
Contributor

A findByOwner implementation that uses batched calls to
getMultipleAccountsInfo (via Account.getInfos) instead of
individual calls to getProgramAccounts per address.

Notes:

  • amount?.toNumber() has been replaced with a direct comparison using BN.js operations as BN.toNumber is limited to 53 bits and some instances where it overflowed were encountered.
  • the return type is MetadataData[] instead of Metadata[] like the existing findByOwner functions

Copy link
Contributor

@kespinola kespinola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excited or this one. Currently, Metaplex storefronts lean on this account provider which subscripts to all the token accounts owned by the logged-in user. This opens up a lot of connections to the WS endpoint of the RPC server which isn't well optimized for heavy use of subscriptions.

https://github.com/metaplex-foundation/metaplex/blob/master/js/packages/common/src/contexts/accounts/accounts.tsx#L123

src/programs/metadata/accounts/Metadata.ts Outdated Show resolved Hide resolved
A `findByOwner` implementation that uses batched calls to
`getMultipleAccountsInfo` (via `Account.getInfos`) instead of
individual calls to `getProgramAccounts` per address.
@kurpav kurpav merged commit 248b61b into metaplex-foundation:main Nov 23, 2021
@solberenson solberenson deleted the findDataByOwner branch November 23, 2021 20:14
@vpontis
Copy link

vpontis commented Dec 22, 2021

Hmm, are there plans to improve this? This call does Promise.all without any limiting — that means for a large wallet this could send 100+ network requests at once which could take down the client / server.

I've used p-limit to get around this.

But an even nicer solution would be to use something like Solana JSON RPC's getMultipleAccounts and then to be smart about parsing the data on each account.

@solberenson
Copy link
Contributor Author

Hmm, are there plans to improve this? This call does Promise.all without any limiting — that means for a large wallet this could send 100+ network requests at once which could take down the client / server.

I've used p-limit to get around this.

But an even nicer solution would be to use something like Solana JSON RPC's getMultipleAccounts and then to be smart about parsing the data on each account.

Apologies for the delayed response, I haven't looked at this since it was merged.

This solution already uses getMultipleAccountsInfo in batches of 99-100 via Account.getInfos.

It makes:

  • a single call to getTokenAccountsByOwner
  • one call to getMultipleAccountsInfo per 100 metadata accounts

The Promise.all is for deriving the metadata addresses; these do not result in network calls.

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

Successfully merging this pull request may close these issues.

6 participants