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

sync armies fix #2585

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions client/src/dojo/debouncedQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, Metadata, Schema } from "@dojoengine/recs";
import { ToriiClient } from "@dojoengine/torii-client";
import debounce from "lodash/debounce";
import {
addArrivalsSubscription,
addDonkeysAndArmiesSubscription,
addHyperstructureSubscription,
addMarketSubscription,
addToSubscription,
Expand Down Expand Up @@ -103,14 +103,14 @@ export const debouncedAddToSubscriptionOneKey = debounce(
{ leading: true },
);

export const debounceAddResourceArrivals = debounce(
export const debounceAddDonkeysAndArmiesSubscription = debounce(
async <S extends Schema>(
client: ToriiClient,
components: Component<S, Metadata, undefined>[],
entityID: number[],
onComplete?: () => void,
) => {
await subscriptionQueue.add(() => addArrivalsSubscription(client, components, entityID), onComplete);
await subscriptionQueue.add(() => addDonkeysAndArmiesSubscription(client, components, entityID), onComplete);
},
Comment on lines +106 to 114
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Type inconsistency confirmed between debounced function and its implementation

The type inconsistency is actually a bug. From the code analysis:

  • debounceAddDonkeysAndArmiesSubscription accepts entityID: number[]

  • But its implementation addDonkeysAndArmiesSubscription expects entityIds: number[] (note the plural form)

  • All other subscription functions consistently use entityID: string[]

  • client/src/dojo/debouncedQueries.ts: Parameter name mismatch between entityID and entityIds

  • client/src/dojo/queries.ts: Consider aligning the type with other subscription functions (string[] instead of number[])

🔗 Analysis chain

Consider type consistency across subscription functions

The entityID parameter is typed as number[] while other similar functions (debouncedAddToSubscription, debouncedAddToSubscriptionOneKey, etc.) use string[]. Please verify if this type difference is intentional.


These commands will help us:

  1. Find all subscription-related functions
  2. See the full context of debouncedQueries.ts
  3. Find function declarations with entityID parameter using AST matching
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for entityID parameter types in subscription functions
ast-grep --pattern 'function $name($params) { $$$}' | rg 'entityID.*\['

Length of output: 73


Script:

#!/bin/bash
# Let's search for all subscription-related functions and their entityID parameter types
rg -A 3 "export (const|function) \w*[Ss]ubscription" 

Length of output: 3839


Script:

#!/bin/bash
# Search specifically in the debouncedQueries.ts file
cat client/src/dojo/debouncedQueries.ts

Length of output: 4739


Script:

#!/bin/bash
# Search for function declarations with entityID parameter
ast-grep --pattern 'export const $_ = $$$entityID: $_$$$'

Length of output: 59

250,
{ leading: true },
Expand Down
35 changes: 5 additions & 30 deletions client/src/dojo/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export const addHyperstructureSubscription = async <S extends Schema>(
console.log("HyperstructureEnd", end - start);
};

export const addArrivalsSubscription = async <S extends Schema>(
export const addDonkeysAndArmiesSubscription = async <S extends Schema>(
client: ToriiClient,
components: Component<S, Metadata, undefined>[],
entityIds: number[],
Expand All @@ -200,35 +200,6 @@ export const addArrivalsSubscription = async <S extends Schema>(
console.log("ArrivalsEnd: starting resource arrivals");
await getEntities(
client,
// todo: waiting on ghlim to check issue with this query
// {
// Composite: {
// operator: "And",
// clauses: [
// {
// Composite: {
// operator: "Or",
// clauses: entityIds.map((id) => ({
// Member: {
// model: "s0_eternum-EntityOwner",
// member: "entity_owner_id",
// operator: "Eq",
// value: { Primitive: { U32: id } },
// },
// })),
// },
// },
// {
// Member: {
// model: "s0_eternum-OwnedResourcesTracker",
// member: "resource_types",
// operator: "Neq",
// value: { Primitive: { U256: "0" } },
// },
// },
// ],
// },
// },
{
Composite: {
operator: "Or",
Expand All @@ -248,10 +219,14 @@ export const addArrivalsSubscription = async <S extends Schema>(
[
"s0_eternum-Army",
"s0_eternum-Position",
"s0_eternum-Health",
"s0_eternum-EntityOwner",
"s0_eternum-Protectee",
"s0_eternum-Stamina",
"s0_eternum-Weight",
"s0_eternum-OwnedResourcesTracker",
"s0_eternum-ArrivalTime",
"s0_eternum-Quantity",
],
1000,
false,
Expand Down
4 changes: 2 additions & 2 deletions client/src/hooks/store/useWorldLoading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export enum LoadingStateKey {
Market = "market",
PlayerStructuresOneKey = "playerStructuresOneKey",
PlayerStructuresTwoKey = "playerStructuresTwoKey",
Arrivals = "arrivals",
DonkeysAndArmies = "donkeysAndArmies",
Map = "map",
Bank = "bank",
World = "world",
Expand All @@ -32,7 +32,7 @@ export const createWorldStoreSlice = (set: any) => ({
[LoadingStateKey.Market]: false,
[LoadingStateKey.PlayerStructuresOneKey]: false,
[LoadingStateKey.PlayerStructuresTwoKey]: false,
[LoadingStateKey.Arrivals]: false,
[LoadingStateKey.DonkeysAndArmies]: false,
[LoadingStateKey.Map]: false,
[LoadingStateKey.Bank]: false,
[LoadingStateKey.World]: false,
Expand Down
2 changes: 1 addition & 1 deletion client/src/ui/components/WorldLoading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const WorldLoading = () => {
if (loadingStates[LoadingStateKey.Market]) items.push("Market");
if (loadingStates[LoadingStateKey.PlayerStructuresOneKey] || loadingStates[LoadingStateKey.PlayerStructuresTwoKey])
items.push("Player Structures");
if (loadingStates[LoadingStateKey.Arrivals]) items.push("Arrivals");
if (loadingStates[LoadingStateKey.DonkeysAndArmies]) items.push("Donkeys and Armies");
if (loadingStates[LoadingStateKey.Map]) items.push("Map");
if (loadingStates[LoadingStateKey.Bank]) items.push("Bank");
if (loadingStates[LoadingStateKey.World]) items.push("World");
Expand Down
8 changes: 4 additions & 4 deletions client/src/ui/layouts/World.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Redirect } from "wouter";
import useUIStore from "../../hooks/store/useUIStore";

import {
debounceAddResourceArrivals,
debounceAddDonkeysAndArmiesSubscription,
debouncedAddHyperstructureSubscription,
debouncedAddMarketSubscription,
debouncedAddToSubscription,
Expand Down Expand Up @@ -164,7 +164,7 @@ export const World = ({ backgroundImage }: { backgroundImage: string }) => {
const fetch = async () => {
setLoading(LoadingStateKey.PlayerStructuresOneKey, true);
setLoading(LoadingStateKey.PlayerStructuresTwoKey, true);
setLoading(LoadingStateKey.Arrivals, true);
setLoading(LoadingStateKey.DonkeysAndArmies, true);

const isSyncing = true;

Expand All @@ -186,11 +186,11 @@ export const World = ({ backgroundImage }: { backgroundImage: string }) => {
),
]);

await debounceAddResourceArrivals(
await debounceAddDonkeysAndArmiesSubscription(
dojo.network.toriiClient,
dojo.network.contractComponents as any,
[...structures.map((structure) => structure.entity_id)],
() => setLoading(LoadingStateKey.Arrivals, false),
() => setLoading(LoadingStateKey.DonkeysAndArmies, false),
);
} catch (error) {
console.error("Fetch failed", error);
Expand Down
Loading