-
Notifications
You must be signed in to change notification settings - Fork 51
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
Raschel sync #2555
Raschel sync #2555
Changes from 3 commits
e6a0195
3ff0406
4fddc1a
080f8ce
40781d9
c12696d
f6b5866
27aeadd
dc94fac
642dee4
4548342
de96dbf
f44e971
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 |
---|---|---|
|
@@ -87,6 +87,9 @@ export class SystemManager { | |
isComponentUpdate(update, this.setup.components.Health) | ||
) { | ||
const army = getComponentValue(this.setup.components.Army, update.entity); | ||
|
||
console.log({ armyUpdates: army }); | ||
|
||
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. 🛠️ Refactor suggestion Remove or conditionally enable debug logging. The console.log statement for army updates could impact performance and clutter the console in production. Consider using a debug flag: +const DEBUG_ARMY_UPDATES = process.env.NODE_ENV === 'development';
const army = getComponentValue(this.setup.components.Army, update.entity);
-console.log({ armyUpdates: army });
+if (DEBUG_ARMY_UPDATES) {
+ console.log({ armyUpdates: army });
+}
|
||
if (!army) return; | ||
|
||
const position = getComponentValue(this.setup.components.Position, update.entity); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { Leva } from "leva"; | ||
import { lazy, Suspense, useEffect, useMemo, useState } from "react"; | ||
import { lazy, Suspense, useEffect } from "react"; | ||
import { Redirect } from "wouter"; | ||
import useUIStore from "../../hooks/store/useUIStore"; | ||
|
||
|
@@ -10,7 +10,7 @@ import { | |
addToSubscriptionTwoKeyModelbyRealmEntityId, | ||
} from "@/dojo/queries"; | ||
import { useDojo } from "@/hooks/context/DojoContext"; | ||
import { PlayerStructure, useEntities } from "@/hooks/helpers/useEntities"; | ||
import { useEntities } from "@/hooks/helpers/useEntities"; | ||
import { useStructureEntityId } from "@/hooks/helpers/useStructureEntityId"; | ||
import { useFetchBlockchainData } from "@/hooks/store/useBlockchainStore"; | ||
import { useWorldStore } from "@/hooks/store/useWorldLoading"; | ||
|
@@ -91,7 +91,6 @@ const MiniMapNavigation = lazy(() => | |
); | ||
|
||
export const World = ({ backgroundImage }: { backgroundImage: string }) => { | ||
const [subscriptions, setSubscriptions] = useState<{ [entity: string]: boolean }>({}); | ||
const showBlankOverlay = useUIStore((state) => state.showBlankOverlay); | ||
const isLoadingScreenEnabled = useUIStore((state) => state.isLoadingScreenEnabled); | ||
|
||
|
@@ -106,7 +105,6 @@ export const World = ({ backgroundImage }: { backgroundImage: string }) => { | |
|
||
// We could optimise this deeper.... | ||
|
||
const worldLoading = useWorldStore((state) => state.isWorldLoading); | ||
const setWorldLoading = useWorldStore((state) => state.setWorldLoading); | ||
const setMarketLoading = useWorldStore((state) => state.setMarketLoading); | ||
|
||
|
@@ -116,62 +114,76 @@ export const World = ({ backgroundImage }: { backgroundImage: string }) => { | |
const { playerStructures } = useEntities(); | ||
const structures = playerStructures(); | ||
|
||
const filteredStructures = useMemo( | ||
() => structures.filter((structure: PlayerStructure) => !subscriptions[structure.entity_id.toString()]), | ||
[structures, subscriptions], | ||
); | ||
|
||
useEffect(() => { | ||
if ( | ||
!structureEntityId || | ||
subscriptions[structureEntityId.toString()] || | ||
subscriptions[ADMIN_BANK_ENTITY_ID.toString()] || | ||
structureEntityId === 999999999 | ||
) { | ||
return; | ||
} | ||
|
||
const position = getComponentValue( | ||
dojo.setup.components.Position, | ||
getEntityIdFromKeys([BigInt(structureEntityId)]), | ||
); | ||
|
||
setWorldLoading(true); | ||
setSubscriptions((prev) => ({ | ||
...prev, | ||
[structureEntityId.toString()]: true, | ||
[ADMIN_BANK_ENTITY_ID.toString()]: true, | ||
...Object.fromEntries(filteredStructures.map((structure) => [structure.entity_id.toString(), true])), | ||
})); | ||
|
||
const fetch = async () => { | ||
try { | ||
await Promise.all([ | ||
addToSubscriptionOneKeyModelbyRealmEntityId( | ||
addToSubscription( | ||
dojo.network.toriiClient, | ||
dojo.network.contractComponents as any, | ||
[...filteredStructures.map((structure) => structure.entity_id.toString())], | ||
[structureEntityId.toString()], | ||
[{ x: position?.x || 0, y: position?.y || 0 }], | ||
), | ||
addToSubscriptionTwoKeyModelbyRealmEntityId( | ||
]); | ||
} catch (error) { | ||
console.error("Fetch failed", error); | ||
} finally { | ||
setWorldLoading(false); | ||
setMarketLoading(false); | ||
} | ||
}; | ||
|
||
fetch(); | ||
}, [structureEntityId]); | ||
|
||
useEffect(() => { | ||
const structuresEntityIds = structures.map((structure) => structure.entity_id.toString()); | ||
|
||
const fetch = async () => { | ||
try { | ||
await Promise.all([ | ||
addToSubscriptionOneKeyModelbyRealmEntityId( | ||
dojo.network.toriiClient, | ||
dojo.network.contractComponents as any, | ||
[...filteredStructures.map((structure) => structure.entity_id.toString())], | ||
structuresEntityIds, | ||
), | ||
addToSubscription( | ||
addToSubscriptionTwoKeyModelbyRealmEntityId( | ||
dojo.network.toriiClient, | ||
dojo.network.contractComponents as any, | ||
[structureEntityId.toString()], | ||
[{ x: position?.x || 0, y: position?.y || 0 }], | ||
structuresEntityIds, | ||
), | ||
addToSubscription(dojo.network.toriiClient, dojo.network.contractComponents as any, structuresEntityIds, [ | ||
...structures.map((structure) => ({ x: structure.position.x, y: structure.position.y })), | ||
]), | ||
]); | ||
} catch (error) { | ||
console.error("Fetch failed", error); | ||
} finally { | ||
setWorldLoading(false); | ||
setMarketLoading(false); | ||
} | ||
}; | ||
|
||
fetch(); | ||
}, [structures]); | ||
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. 🛠️ Refactor suggestion Optimize batch fetching for structures. The current implementation makes multiple API calls in parallel for each structure. Consider batching these calls to reduce network overhead. Consider consolidating the API calls: const fetch = async () => {
try {
+ const batchSize = 50;
+ const batches = [];
+ for (let i = 0; i < structuresEntityIds.length; i += batchSize) {
+ const batch = structuresEntityIds.slice(i, i + batchSize);
await Promise.all([
addToSubscriptionOneKeyModelbyRealmEntityId(
dojo.network.toriiClient,
dojo.network.contractComponents as any,
- structuresEntityIds,
+ batch,
),
addToSubscriptionTwoKeyModelbyRealmEntityId(
dojo.network.toriiClient,
dojo.network.contractComponents as any,
- structuresEntityIds,
+ batch,
),
]);
+ }
} catch (error) {
console.error("Fetch failed", error);
}
};
|
||
|
||
useEffect(() => { | ||
setWorldLoading(true); | ||
|
||
const fetch = async () => { | ||
try { | ||
await Promise.all([ | ||
addToSubscription(dojo.network.toriiClient, dojo.network.contractComponents as any, [ | ||
ADMIN_BANK_ENTITY_ID.toString(), | ||
]), | ||
addToSubscription( | ||
dojo.network.toriiClient, | ||
dojo.network.contractComponents as any, | ||
[...filteredStructures.map((structure) => structure.entity_id.toString())], | ||
[...filteredStructures.map((structure) => ({ x: structure.position.x, y: structure.position.y }))], | ||
), | ||
|
||
addMarketSubscription(dojo.network.toriiClient, dojo.network.contractComponents as any), | ||
]); | ||
} catch (error) { | ||
|
@@ -183,7 +195,7 @@ export const World = ({ backgroundImage }: { backgroundImage: string }) => { | |
}; | ||
|
||
fetch(); | ||
}, [structureEntityId, subscriptions, setWorldLoading, setSubscriptions, filteredStructures]); | ||
}, []); | ||
|
||
return ( | ||
<div | ||
|
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.
💡 Codebase verification
Both
Army
andEntityOwner
components are actively used in the codebaseThe components marked for improvement are actually critical parts of the system:
Army
component is used in battle systems and army-related operations (create, delete, buy troops, merge troops)EntityOwner
component is used in conjunction with Army components for ownership trackingCommenting them out in the entity fetch configuration (
setup.ts
) while they're still actively used elsewhere could lead to synchronization issues.client/src/dojo/setup.ts
🔗 Analysis chain
Clarify the improvement plan for commented-out entities.
The commented-out entities
"s0_eternum-Army"
and"s0_eternum-EntityOwner"
are marked with "improve" comments, but there's no clear indication of the improvement plan or why they were commented out.Let's verify if these entities are still being used:
Would you like me to help create a GitHub issue to track the improvement plan for these entities?
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 99
Script:
Length of output: 1761
Script:
Length of output: 7823