From 9440bbe2ab7e8d4a5b7c3859c7db85542900c58b Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Sun, 25 Jan 2026 20:56:07 -0600 Subject: [PATCH] Performance: Removed unnecessary double wait that was causing fetching of channel data to not run in parallel. --- frontend/src/components/tables/ChannelsTable.jsx | 4 ++-- frontend/src/utils.js | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/tables/ChannelsTable.jsx b/frontend/src/components/tables/ChannelsTable.jsx index f9780139..45d46f17 100644 --- a/frontend/src/components/tables/ChannelsTable.jsx +++ b/frontend/src/components/tables/ChannelsTable.jsx @@ -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); diff --git a/frontend/src/utils.js b/frontend/src/utils.js index 81836f0a..bb1b6060 100644 --- a/frontend/src/utils.js +++ b/frontend/src/utils.js @@ -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