Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ export const Connection: React.FC<Props> = ({ appId }) => {
refetchInterval: shouldRefetch ? 2500 : undefined,
}
);
const [numApiKeys] = api.user.apiKeys.count.useSuspenseQuery({ appId });
const [numApiKeys] = api.user.apiKeys.count.useSuspenseQuery(
{ appId },
{
refetchInterval: shouldRefetch ? 2500 : undefined,
}
);

const isConnected = useMemo(() => {
return numTokens > 0 || numApiKeys > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,10 @@ export const useAppConnectionSetup = (appId: string) => {
refetchInterval: shouldRefetchConnection ? 2500 : undefined,
}
);
const [transactionsCount] = api.apps.app.transactions.count.useSuspenseQuery(
{
appId,
},
{
refetchInterval: shouldRefetchTransactions ? 2500 : undefined,
}
Comment on lines -28 to -34

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why are we removing transaction count here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

(Lines 45-52) and (Lines 28-34). Both queries were fetching the exact same data from the exact same endpoint!
Both queries would make separate API calls every 2.5 seconds.

The core bug: isConnected should only check if the connection is set up (OAuth tokens OR API keys exist), NOT whether transactions have been made.

If a user made transactions but deleted their API key, isConnected would still be true (wrong!)
The logic mixed two separate concepts: connection setup vs. usage
Different polling strategies for the same data caused race conditions

So kept second query.

);

const isConnected = useMemo(() => {
return numTokens > 0 || numApiKeys > 0 || transactionsCount > 0;
}, [numTokens, numApiKeys, transactionsCount]);
return numTokens > 0 || numApiKeys > 0;
}, [numTokens, numApiKeys]);

useEffect(() => {
setShouldRefetchConnection(!isConnected);
Expand Down
Loading