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

Refactor dynamodb saving, add secondary index #28

Merged
merged 15 commits into from
Aug 8, 2022

Conversation

timjrobinson
Copy link
Contributor

@timjrobinson timjrobinson commented Jul 21, 2022

We need the ability for the GraphQL endpoint to filter by pools that have > n totalShares and to be able to sort by totalLiquidity and possibly other things in the future. The problem is these are stored as strings in DynamoDB so aren't query-able as numbers. I was previously just using Number() before saving but this only allows 16 significant digits and rounds larger numbers so we lose precision.

This is a refactor to insert the data with types specified for every field so that we can have strings in JavaScript but numbers in the database (and we can easily specify the types for all fields in the future). It adds a schema which is equivalent to the graphQL schema and specifies fields that are BigNumbers or Numbers. Both are stored in DynamoDB as numbers, but BigNumbers are strings in Javascript and Numbers are Numbers.

This PR also adds a secondary index to the pools table of chainid + totalLiquidity so we can easily query for all pools on a chain sorted by totalLiquidity.

- Some pool attributes are stored as strings in Javascript by should be
numbers in DynamoDB so they can be compared with gt/lt and used as
indexes. For example: totalShares and totalLiquidity. To do this we need
to change the way DynamoDB inserts data to specify the exact type of
each field and specify that these BigNumber fields should be numbers.
- Remove a lot of console.logs and change them to debug logs instead.
@timjrobinson timjrobinson marked this pull request as ready for review July 22, 2022 01:17
@timjrobinson timjrobinson changed the title Refactor dynamodb saving Refactor dynamodb saving, add secondary index Jul 22, 2022
Copy link
Collaborator

@garethfuller garethfuller left a comment

Choose a reason for hiding this comment

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

Again, not much I can really comment on here but it looks good.

Comment on lines +62 to +65
case 'Number':
default:
unmarshalledItem[key] = Number(value.value)
break;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the Number case be handled here and why is there his break statement at the bottom?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Number just falls through to the default. Don't need the break at the bottom I guess

@timjrobinson timjrobinson merged commit 27c43d9 into master Aug 8, 2022
@timjrobinson timjrobinson deleted the refactor-dynamodb-saving branch August 8, 2022 02:17
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.

2 participants