Performance: Removed unnecessary double wait that was causing fetching of channel data to not run in parallel.

This commit is contained in:
SergeantPanda 2026-01-25 20:56:07 -06:00
parent 655760f652
commit 9440bbe2ab
2 changed files with 16 additions and 4 deletions

View file

@ -463,8 +463,8 @@ const ChannelsTable = ({ onReady }) => {
try {
const [results, ids] = await Promise.all([
await API.queryChannels(params),
await API.getAllChannelIds(params),
API.queryChannels(params),
API.getAllChannelIds(params),
]);
setIsLoading(false);

View file

@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useRef } from 'react';
export default {
Limiter: (n, list) => {
@ -40,13 +40,25 @@ export default {
// Custom debounce hook
export function useDebounce(value, delay = 500, callback = null) {
const [debouncedValue, setDebouncedValue] = useState(value);
const isFirstRender = useRef(true);
const previousValueRef = useRef(JSON.stringify(value));
useEffect(() => {
const currentValueStr = JSON.stringify(value);
// Skip if value hasn't actually changed (prevents unnecessary state updates)
if (previousValueRef.current === currentValueStr) {
return;
}
const handler = setTimeout(() => {
setDebouncedValue(value);
if (callback) {
// Only fire callback if not the first render
if (callback && !isFirstRender.current) {
callback();
}
isFirstRender.current = false;
previousValueRef.current = currentValueStr;
}, delay);
return () => clearTimeout(handler); // Cleanup timeout on unmount or value change