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(store-indexer,store-sync): filter findAll by tableIds #1572

Merged
merged 6 commits into from
Sep 29, 2023

Conversation

holic
Copy link
Member

@holic holic commented Sep 22, 2023

pulled out of #1571

@changeset-bot
Copy link

changeset-bot bot commented Sep 22, 2023

⚠️ No Changeset found

Latest commit: 941c863

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@holic holic marked this pull request as ready for review September 22, 2023 21:51
@holic holic changed the title feat(store-indexer,store-sync): support filtering indexer query by tableIds feat(store-indexer,store-sync): filter findAll by tableIds Sep 22, 2023
@holic
Copy link
Member Author

holic commented Sep 28, 2023

we should probably default-include all store/world tables since weird things happen if these are ignored/excluded

@alvrs alvrs added this to the MUD stable milestone Sep 28, 2023
@holic
Copy link
Member Author

holic commented Sep 29, 2023

can also filter events by table IDs

@holic
Copy link
Member Author

holic commented Sep 29, 2023

can't filter logs by topics/table IDs yet: #1658

const includedTableIds = new Set(tableIds.length ? [...internalTableIds, ...tableIds] : []);
const tables = (await getTables(database))
.filter((table) => address == null || getAddress(address) === getAddress(table.address))
.filter((table) => !includedTableIds.size || includedTableIds.has(table.tableId));
Copy link
Member

Choose a reason for hiding this comment

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

general q, not related to this PR: should we combine this adapter with the one defined in sqlite?

On the same note, a couple lines below this we have const sqliteTable = builtTable(table), should that be postgresTable? Is it the same object type? (Can't comment directly on it bc it didn't change in this PR)

Copy link
Member Author

Choose a reason for hiding this comment

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

I would like to, but there's some API differences between drizzle's postgres and sqlite adapters that makes it hard to combine these.

Also the sqlite patterns here are a bit behind - I cleaned things up in the postgres, but didn't go back to refactor sqlite to match.

startBlock: initialStartBlock = 0n,
maxBlockRange,
initialState,
indexerUrl,
}: CreateStoreSyncOptions<TConfig>): Promise<SyncResult> {
const includedTableIds = new Set(tableIds.length ? [...internalTableIds, ...tableIds] : []);
Copy link
Member

Choose a reason for hiding this comment

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

it looks like we actively pass internalTableIds here, but also always include it internally in the query adapter - doesn't really hurt bc it's a set, but feels like it could be confusing (e.g. someone removing internalTableIds here and then wondering why they still show up in the results). What are your thoughts on only putting it in one of the two places and making it an explicit assumption? (e.g. "findAll always returns internal tables", or "findAll returns only the tables passed in the query, it is recommended internal tables are always included in the query")

Copy link
Member Author

Choose a reason for hiding this comment

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

I think making the indexer dumber (uses whatever you pass in for table IDs) makes sense, and only the store-sync includes internal table IDs.


export const storeTableIds = Object.keys(storeConfig.tables).map((name) =>
resourceIdToHex({
type: storeConfig.tables[name as keyof typeof storeConfig.tables].offchainOnly ? "offchainTable" : "table",
Copy link
Member

Choose a reason for hiding this comment

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

as keyof typeof storeConfig.table sad that typescript can't infer that from Object.keys(storeConfig.tables) 😢

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed! I think lodash has a thing for this, just waiting for them to finish their TS rewrite

alvrs
alvrs previously approved these changes Sep 29, 2023
Copy link
Member

@alvrs alvrs left a comment

Choose a reason for hiding this comment

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

nothing blocking!

@holic holic merged commit 4998d69 into main Sep 29, 2023
10 checks passed
@holic holic deleted the holic/indexer-tableids branch September 29, 2023 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

2 participants