Skip to content

Commit

Permalink
useCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
skull8888888 committed Jan 9, 2025
1 parent 75a2ac5 commit 0dfb838
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions frontend/components/traces/timeline.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from 'react';
import { useCallback, useEffect, useRef, useState } from 'react';

import { getDuration } from '@/lib/flow/utils';
import { Span } from '@/lib/traces/types';
Expand Down Expand Up @@ -31,26 +31,25 @@ export default function Timeline({ spans, childSpans, collapsedSpans }: Timeline
const [timeIntervals, setTimeIntervals] = useState<string[]>([]);
const ref = useRef<HTMLDivElement>(null);

const traverse = (
span: Span,
childSpans: { [key: string]: Span[] },
orderedSpands: Span[]
) => {
if (!span) {
return;
}
orderedSpands.push(span);
const traverse = useCallback(
(span: Span, childSpans: { [key: string]: Span[] }, orderedSpands: Span[]) => {
if (!span) {
return;
}
orderedSpands.push(span);

if (collapsedSpans.has(span.spanId)) {
return;
}
if (collapsedSpans.has(span.spanId)) {
return;
}

if (childSpans[span.spanId]) {
for (const child of childSpans[span.spanId]) {
traverse(child, childSpans, orderedSpands);
if (childSpans[span.spanId]) {
for (const child of childSpans[span.spanId]) {
traverse(child, childSpans, orderedSpands);
}
}
}
};
},
[collapsedSpans]
);

useEffect(() => {
if (!ref.current || childSpans === null) {
Expand Down

0 comments on commit 0dfb838

Please sign in to comment.