-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(store-indexer,store-sync): filter by table and key (#1794)
Co-authored-by: alvarius <[email protected]>
- Loading branch information
Showing
26 changed files
with
533 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
"@latticexyz/store-indexer": major | ||
--- | ||
|
||
Removed `tableIds` filter option in favor of the more flexible `filters` option that accepts `tableId` and an optional `key0` and/or `key1` to filter data by tables and keys. | ||
|
||
If you were using an indexer client directly, you'll need to update your query: | ||
|
||
```diff | ||
await indexer.findAll.query({ | ||
chainId, | ||
address, | ||
- tableIds: ['0x...'], | ||
+ filters: [{ tableId: '0x...' }], | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
"@latticexyz/store-sync": minor | ||
--- | ||
|
||
Added a `filters` option to store sync to allow filtering client data on tables and keys. Previously, it was only possible to filter on `tableIds`, but the new filter option allows for more flexible filtering by key. | ||
|
||
If you are building a large MUD application, you can use positional keys as a way to shard data and make it possible to load only the data needed in the client for a particular section of your app. We're using this already in Sky Strife to load match-specific data into match pages without having to load data for all matches, greatly improving load time and client performance. | ||
|
||
```ts | ||
syncToRecs({ | ||
... | ||
filters: [{ tableId: '0x...', key0: '0x...' }], | ||
}); | ||
``` | ||
|
||
The `tableIds` option is now deprecated and will be removed in the future, but is kept here for backwards compatibility. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.21; | ||
|
||
import { Script } from "forge-std/Script.sol"; | ||
import { console } from "forge-std/console.sol"; | ||
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; | ||
import { IWorld } from "../src/codegen/world/IWorld.sol"; | ||
|
||
import { Position } from "../src/codegen/index.sol"; | ||
|
||
contract PostDeploy is Script { | ||
function run(address worldAddress) external { | ||
StoreSwitch.setStoreAddress(worldAddress); | ||
|
||
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
vm.startBroadcast(deployerPrivateKey); | ||
|
||
// Set up a bunch of position data so we can demonstrate filtering | ||
Position.set({ zone: "map1", x: 1, y: 1, player: msg.sender }); | ||
Position.set({ zone: "map1", x: 2, y: -2, player: msg.sender }); | ||
Position.set({ zone: "map2", x: 0, y: -99, player: msg.sender }); | ||
Position.set({ zone: "map2", x: 0, y: 99, player: msg.sender }); | ||
Position.set({ zone: "map99", x: 99, y: 99, player: msg.sender }); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.