Skip to content

Commit

Permalink
Merge pull request #275 from moonstream-to/token-stat-fetch-optimization
Browse files Browse the repository at this point in the history
Token stat fetch optimization
  • Loading branch information
Anton-Mushnin authored May 8, 2024
2 parents 442561d + c3cf60c commit e6123a1
Show file tree
Hide file tree
Showing 14 changed files with 6 additions and 54 deletions.
2 changes: 0 additions & 2 deletions web/src/components/HomePage/PvpView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const PvpView = ({ atBats, tokens }: { atBats: AtBat[]; tokens: OwnedToken[] })
queryClient.setQueryData(
["atBats"],
(oldData: { atBats: AtBat[]; tokens: Token[] } | undefined) => {
console.log(oldData);
if (!oldData) {
return { atBats: [], tokens: [] };
}
Expand All @@ -64,7 +63,6 @@ const PvpView = ({ atBats, tokens }: { atBats: AtBat[]; tokens: OwnedToken[] })
},
);
queryClient.setQueryData(["owned_tokens", user], (oldData: OwnedToken[] | undefined) => {
console.log(oldData);
if (!oldData) {
return [];
}
Expand Down
1 change: 0 additions & 1 deletion web/src/components/Playing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const Playing = () => {
const ownedTokens = useQuery<OwnedToken[]>(
["owned_tokens", user],
async () => {
console.log("FETCHING TOKENS");
const ownedTokens = user ? await fetchFullcountPlayerTokens() : [];
if (ownedTokens.length > 0 && !selectedToken && ownedTokens[selectedTokenIdx]) {
updateContext({ selectedToken: { ...ownedTokens[selectedTokenIdx] } });
Expand Down
1 change: 0 additions & 1 deletion web/src/components/atbat/AtBatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ const AtBatView: React.FC = () => {
},
{
onSuccess: (data) => {
console.log(data);
if (data && !selectedToken && ownedTokens.data) {
const token = ownedTokens.data.find(
(t) => isSameToken(t, data.atBat.batter) || isSameToken(t, data.atBat.pitcher),
Expand Down
8 changes: 4 additions & 4 deletions web/src/components/atbat/TokenCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const TokenCard = ({ token, isPitcher }: { token: Token; isPitcher: boolean }) =
retry: (failureCount) => {
return failureCount < 3;
},
refetchInterval: 5000,
refetchInterval: 50000,
},
);

Expand All @@ -56,7 +56,7 @@ const TokenCard = ({ token, isPitcher }: { token: Token; isPitcher: boolean }) =
retry: (failureCount) => {
return failureCount < 3;
},
refetchInterval: 5000,
refetchInterval: 50000,
},
);

Expand Down Expand Up @@ -93,7 +93,7 @@ const TokenCard = ({ token, isPitcher }: { token: Token; isPitcher: boolean }) =
retry: (failureCount) => {
return failureCount < 3;
},
refetchInterval: 5000,
refetchInterval: 50000,
},
);

Expand Down Expand Up @@ -127,7 +127,7 @@ const TokenCard = ({ token, isPitcher }: { token: Token; isPitcher: boolean }) =
retry: (failureCount) => {
return failureCount < 3;
},
refetchInterval: 5000,
refetchInterval: 50000,
},
);
return (
Expand Down
1 change: 0 additions & 1 deletion web/src/components/campaign/CharacterCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const CharacterCard = ({
queryClient.setQueryData(
["atBats"],
(oldData: { atBats: AtBat[]; tokens: Token[] } | undefined) => {
console.log(oldData);
if (!oldData) {
return { atBats: [], tokens: [] };
}
Expand Down
1 change: 0 additions & 1 deletion web/src/components/leaderboard/leaderboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export const fetchWindowsForTokens = async (
return res.data;
});
const response = await Promise.all(promises);
console.log(response);
const windows = response.map((window: any) =>
window.map((entry: { address: string }) => {
const [address, id] = entry.address.split("_");
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/playing/MainStat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const pitcherRecord = (stats: PlayerStats): string => {
const MainStat = ({ stats, isPitcher }: { stats: PlayerStats; isPitcher: boolean }) => {
return (
<>
{isPitcher && stats && stats.points_data?.pitching_data && (
{isPitcher && !!stats && !!stats.points_data?.pitching_data && (
<Flex className={styles.container}>
<Text className={styles.data}>{pitcherRecord(stats)}</Text>
<Text className={styles.label}>W-L</Text>
Expand All @@ -44,7 +44,7 @@ const MainStat = ({ stats, isPitcher }: { stats: PlayerStats; isPitcher: boolean
<Text className={styles.label}>WHIP</Text>
</Flex>
)}
{!isPitcher && stats && stats.points_data?.batting_data && (
{!isPitcher && !!stats && !!stats.points_data?.batting_data && (
<Flex className={styles.container}>
<Text className={styles.data}>
{formatDecimal(stats.points_data.batting_data.batting_average)}
Expand Down
28 changes: 0 additions & 28 deletions web/src/components/playing/PlayView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,11 @@ const PlayView = ({ selectedToken }: { selectedToken: Token }) => {
const atBat = useQuery(
["sessionAtBatID", selectedSession],
() => {
console.log("sessionAtBatID");
if (!selectedSession) return undefined;
return gameContract.methods.SessionAtBat(selectedSession.sessionID).call();
},
{
refetchInterval: 100000000,
onSuccess: (data) => {
console.log("sessionAtBatID success: ", data);
},
},
);

Expand All @@ -114,10 +110,8 @@ const PlayView = ({ selectedToken }: { selectedToken: Token }) => {
["atBatStatus", atBat.data?.progress],
async () => {
if (!atBat.data) {
console.log("!atBat.data");
return;
}
console.log("atBatStatus", atBat.data);

const atBatID = atBat.data;
const status = await gameContract.methods.getAtBat(atBatID).call();
Expand All @@ -127,13 +121,6 @@ const PlayView = ({ selectedToken }: { selectedToken: Token }) => {
const currentSessionID = await gameContract.methods
.AtBatSessions(atBatID, numSessions - 1)
.call();
console.log({
atBat: {
...status,
currentSessionID,
numSessions,
},
});
if (Number(status.outcome) !== 0) {
queryClient.refetchQueries("owned_tokens");
}
Expand All @@ -145,16 +132,12 @@ const PlayView = ({ selectedToken }: { selectedToken: Token }) => {
},
{
enabled: false,
onSuccess: (data) => {
console.log("atBatStatus success: ", data);
},
},
);

const sessionStatus = useQuery(
["session", selectedSession, atBatStatus.data, sessionID],
async () => {
console.log("sessionStatus");
if (!selectedSession) return undefined;
const id = sessionID ?? selectedSession.sessionID;
if (!secondsPerPhase) {
Expand Down Expand Up @@ -274,9 +257,6 @@ const PlayView = ({ selectedToken }: { selectedToken: Token }) => {
},

{
onSuccess: (data) => {
console.log("sessionStatus success: ", data);
},
refetchInterval: 3000,
retry: false,
},
Expand All @@ -288,20 +268,12 @@ const PlayView = ({ selectedToken }: { selectedToken: Token }) => {
}, [selectedToken, opponent]);

useEffect(() => {
console.log("sessionStatus.data useEffect:", sessionStatus.data?.progress);
if (sessionStatus.data) {
atBatStatus.refetch();
}
}, [sessionStatus.data?.progress]);

useEffect(() => {
console.log(
"atBatStatus.data, isShowOutcomeDone useEffect: ",
atBatStatus.data,
isShowOutcomeDone,
"sessionID: ",
sessionID,
);
if (isShowOutcomeDone && atBatStatus.data?.currentSessionID) {
if (Number(atBatStatus.data.currentSessionID) !== sessionStatus.data?.sessionID) {
setSessionID(atBatStatus.data.currentSessionID);
Expand Down
7 changes: 0 additions & 7 deletions web/src/components/playing/PlayerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,6 @@ const PlayerView = ({
}, [sessionStatus.sessionID]);

useEffect(() => {
console.log(
isPitcher,
sessionStatus.progress,
sessionStatus.didBatterReveal,
sessionStatus.didPitcherReveal,
token.source,
);
if (isPitcher && sessionStatus.progress === 4 && !sessionStatus.didPitcherReveal) {
handleReveal();
}
Expand Down
2 changes: 0 additions & 2 deletions web/src/components/practice/PracticeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const PracticeSelect = () => {
queryClient.setQueryData(
["atBats"],
(oldData: { atBats: AtBat[]; tokens: Token[] } | undefined) => {
console.log(oldData);
if (!oldData) {
return { atBats: [], tokens: [] };
}
Expand All @@ -71,7 +70,6 @@ const PracticeSelect = () => {
},
);
queryClient.setQueryData(["owned_tokens", user], (oldData: OwnedToken[] | undefined) => {
console.log(oldData);
if (!oldData) {
return [];
}
Expand Down
1 change: 0 additions & 1 deletion web/src/components/tokens/OwnedTokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ const OwnedTokens = ({

const mintToken = useMutation(
async ({ name, imageIndex, source }: { name: string; imageIndex: number; source: string }) => {
console.log(imageIndex);
switch (source) {
case "BLBContract":
return mintBLBToken({ web3ctx, name, imageIndex });
Expand Down
1 change: 0 additions & 1 deletion web/src/contexts/GameContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export const GameContextProvider: FC<ProviderProps> = ({ children }) => {
}, [contextState.userSessionId]);

const updateContext = (newState: Partial<GameContextProps>) => {
console.log("updating context: ", { newState });
setContextState((prevState) => {
const isTokenSelected =
prevState.isTokenSelected || !!newState.selectedToken || !!prevState.selectedToken;
Expand Down
1 change: 0 additions & 1 deletion web/src/hooks/useSendReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const useSendReport = () => {
`report_version:${HUMBUG_REPORT_VERSION}`,
],
};
console.log("Sending data:", data);

await axios.post("https://spire.bugout.dev/humbug/reports?sync=true", data, {
headers: {
Expand Down
2 changes: 0 additions & 2 deletions web/src/services/fullcounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const FullcountABI = FullcountABIImported as unknown as AbiItem[];
const AT_BATS_OFFSET = 400;

export const getAtBat = async ({ tokensCache, id }: { tokensCache: Token[]; id: number }) => {
console.log("FETCHING ATBAT", id);
const { gameContract } = getContracts();
const callData = [
gameContract.methods.AtBatState(id).encodeABI(),
Expand Down Expand Up @@ -138,7 +137,6 @@ export const getAtBat = async ({ tokensCache, id }: { tokensCache: Token[]; id:
};

export const getAtBats = async ({ tokensCache }: { tokensCache: Token[] }) => {
console.log("FETCHING ATBATS");
const { gameContract } = getContracts();
const numAtBats = Number(await gameContract.methods.NumAtBats().call());
const oldestAtBatNumber = Math.max(numAtBats - AT_BATS_OFFSET, 1);
Expand Down

0 comments on commit e6123a1

Please sign in to comment.