mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-07-23 18:18:18 +00:00
Performance: Removed unnecessary double wait that was causing fetching of channel data to not run in parallel.
This commit is contained in:
parent
655760f652
commit
9440bbe2ab
2 changed files with 16 additions and 4 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue