-
Notifications
You must be signed in to change notification settings - Fork 183
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
Changes from 5 commits
5d06ad2
a5655ab
4f4c7e7
004b0c4
72033de
941c863
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ import { createIndexerClient } from "./trpc-indexer"; | |
import { SyncStep } from "./SyncStep"; | ||
import { chunk, isDefined } from "@latticexyz/common/utils"; | ||
import { encodeKey, encodeValueArgs } from "@latticexyz/protocol-parser"; | ||
import { internalTableIds } from "./internalTableIds"; | ||
|
||
const debug = parentDebug.extend("createStoreSync"); | ||
|
||
|
@@ -49,13 +50,15 @@ type CreateStoreSyncOptions<TConfig extends StoreConfig = StoreConfig> = SyncOpt | |
export async function createStoreSync<TConfig extends StoreConfig = StoreConfig>({ | ||
storageAdapter, | ||
onProgress, | ||
address, | ||
publicClient, | ||
address, | ||
tableIds = [], | ||
startBlock: initialStartBlock = 0n, | ||
maxBlockRange, | ||
initialState, | ||
indexerUrl, | ||
}: CreateStoreSyncOptions<TConfig>): Promise<SyncResult> { | ||
const includedTableIds = new Set(tableIds.length ? [...internalTableIds, ...tableIds] : []); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks like we actively pass There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
const initialState$ = defer( | ||
async (): Promise< | ||
| { | ||
|
@@ -79,7 +82,7 @@ export async function createStoreSync<TConfig extends StoreConfig = StoreConfig> | |
|
||
const indexer = createIndexerClient({ url: indexerUrl }); | ||
const chainId = publicClient.chain?.id ?? (await publicClient.getChainId()); | ||
const result = await indexer.findAll.query({ chainId, address }); | ||
const result = await indexer.findAll.query({ chainId, address, tableIds: Array.from(includedTableIds) }); | ||
|
||
onProgress?.({ | ||
step: SyncStep.SNAPSHOT, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./common"; | ||
export * from "./createStoreSync"; | ||
export * from "./internalTableIds"; | ||
export * from "./SyncStep"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { resourceIdToHex } from "@latticexyz/common"; | ||
import storeConfig from "@latticexyz/store/mud.config"; | ||
import worldConfig from "@latticexyz/world/mud.config"; | ||
|
||
// TODO: refactor config to include table IDs (https://github.com/latticexyz/mud/pull/1561) | ||
|
||
export const storeTableIds = Object.keys(storeConfig.tables).map((name) => | ||
resourceIdToHex({ | ||
type: storeConfig.tables[name as keyof typeof storeConfig.tables].offchainOnly ? "offchainTable" : "table", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
namespace: storeConfig.namespace, | ||
name, | ||
}) | ||
); | ||
|
||
const worldTableIds = Object.keys(worldConfig.tables).map((name) => | ||
resourceIdToHex({ | ||
type: worldConfig.tables[name as keyof typeof worldConfig.tables].offchainOnly ? "offchainTable" : "table", | ||
namespace: worldConfig.namespace, | ||
name, | ||
}) | ||
); | ||
|
||
export const internalTableIds = [...storeTableIds, ...worldTableIds]; |
There was a problem hiding this comment.
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 bepostgresTable
? Is it the same object type? (Can't comment directly on it bc it didn't change in this PR)There was a problem hiding this comment.
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.