Skip to content

Commit

Permalink
Merge pull request #1868 from zeitgeistpm/tr-react-query-checks
Browse files Browse the repository at this point in the history
Add staleTime to queries
  • Loading branch information
Robiquet authored Oct 10, 2023
2 parents a0085ca + 1397ec6 commit 2da8297
Show file tree
Hide file tree
Showing 16 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/hooks/queries/useAccountTokenPositions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const useAccountTokenPositions = (address?: string) => {
keepPreviousData: true,
enabled: Boolean(sdk && isIndexedSdk(sdk) && address),
refetchInterval: 12 * 1000,
staleTime: Infinity,
},
);
};
1 change: 1 addition & 0 deletions lib/hooks/queries/useAvatarParts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const useAvatarParts = (
{
enabled,
keepPreviousData: true,
staleTime: 100_000,
},
);
};
Expand Down
1 change: 1 addition & 0 deletions lib/hooks/queries/useCategoryCounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const useCategoryCounts = () => {
{
enabled: Boolean(sdk && isIndexedSdk(sdk)),
keepPreviousData: true,
staleTime: 100_000,
},
);

Expand Down
3 changes: 1 addition & 2 deletions lib/hooks/queries/useFeePayingAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ export const useFeePayingAsset = (
const query = useQuery(
[
feePayingAssetKey,
activeAccount,
activeAccount,
activeAccount?.address,
nativeBalance,
dotBalance,
baseFee,
Expand Down
1 change: 1 addition & 0 deletions lib/hooks/queries/useIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const useIdentity = (address?: string) => {
},
{
enabled: Boolean(sdk && isRpcSdk(sdk)),
staleTime: 100_000,
},
);

Expand Down
1 change: 1 addition & 0 deletions lib/hooks/queries/useInfiniteMarkets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const useInfiniteMarkets = (
);
});
},
staleTime: 10_000,
});
return query;
};
2 changes: 2 additions & 0 deletions lib/hooks/queries/useMarket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const useMarket = (
},
{
refetchInterval: opts?.refetchInterval ?? false,
staleTime: 10_000,
enabled: Boolean(
sdk &&
isIndexedSdk(sdk) &&
Expand Down Expand Up @@ -74,6 +75,7 @@ const batcher = memoize((sdk: Sdk<IndexerContext>) => {
});
return markets;
},

scheduler: batshit.windowScheduler(10),
resolver: (data, query) => {
if ("marketId" in query) {
Expand Down
1 change: 1 addition & 0 deletions lib/hooks/queries/useMarketDisputes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const useMarketDisputes = (market: Market<Context> | number) => {
},
{
enabled: Boolean(sdk && isRpcSdk(sdk)),
staleTime: 100_000,
},
);
return query;
Expand Down
3 changes: 2 additions & 1 deletion lib/hooks/queries/useMarketEventHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { MarketEvent } from "lib/gql/market-history";
import { useMarket } from "./useMarket";
import { getMarketHistory } from "lib/gql/market-history";

export const marketsEventsRootQuery = "marketsEvents";
export const marketsEventsRootQuery = "market-events";

export type MarketEventHistory = {
start: MarketEvent;
Expand Down Expand Up @@ -63,6 +63,7 @@ export const useMarketEventHistory = (
},
{
enabled: Boolean(sdk && isIndexedSdk(sdk) && isRpcSdk(sdk) && market),
staleTime: 10_000,
},
);
};
3 changes: 2 additions & 1 deletion lib/hooks/queries/useMarketPriceHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TimeUnit } from "components/ui/TimeFilters";
import { gql, GraphQLClient } from "graphql-request";
import { useSdkv2 } from "../useSdkv2";

export const marketPriceHistoryKey = "market-price-histroy";
export const marketPriceHistoryKey = "market-price-history";

const priceHistoryQuery = gql`
query PriceHistory(
Expand Down Expand Up @@ -56,6 +56,7 @@ export const useMarketPriceHistory = (
enabled: Boolean(
sdk && marketId != null && timeUnit && timeValue && startTime,
),
staleTime: 10_000,
},
);

Expand Down
1 change: 1 addition & 0 deletions lib/hooks/queries/useMarketStage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const useMarketStage = (market?: Market<Context>) => {
},
{
enabled: Boolean(sdk && isRpcSdk(sdk) && market && now),
staleTime: 10_000,
},
);
};
3 changes: 2 additions & 1 deletion lib/hooks/queries/useMarketsStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isIndexedSdk } from "@zeitgeistpm/sdk-next";
import { getMarketsStats, MarketStats } from "lib/gql/markets-stats";
import { useSdkv2 } from "../useSdkv2";

export const marketsStatsRootQuery = "marketsStats";
export const marketsStatsRootQuery = "markets-stats";

export const useMarketsStats = (
marketIds: number[],
Expand All @@ -21,6 +21,7 @@ export const useMarketsStats = (
{
enabled: sdk != null && isIndexedSdk(sdk) && marketIds.length > 0,
keepPreviousData: true,
staleTime: 100_000,
},
);
};
1 change: 1 addition & 0 deletions lib/hooks/queries/usePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const usePool = (getPoolQuery?: PoolGetQuery) => {
},
{
enabled: Boolean(sdk && getPoolQuery && isIndexedSdk(sdk)),
staleTime: 10_000,
},
);

Expand Down
1 change: 1 addition & 0 deletions lib/hooks/queries/useReadyToReportMarkets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const useReadyToReportMarkets = (account?: string) => {
{
enabled: Boolean(enabled),
refetchInterval: 1000 * 60,
staleTime: Infinity,
},
);
};
1 change: 1 addition & 0 deletions lib/hooks/queries/useRedeemableMarkets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const useRedeemableMarkets = (account?: string) => {
},
{
enabled: Boolean(enabled),
staleTime: 100_000,
},
);
};
1 change: 1 addition & 0 deletions lib/hooks/queries/useSimilarMarkets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const useSimilarMarkets = (marketId?: number, limit = 2) => {
},
{
enabled: Boolean(enabled),
staleTime: Infinity,
},
);

Expand Down

0 comments on commit 2da8297

Please sign in to comment.