Skip to content

Commit

Permalink
use duration
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkav committed Jun 7, 2024
1 parent b455195 commit 8a51595
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 23 deletions.
6 changes: 2 additions & 4 deletions packages/insomnia/src/network/request-timing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ type StepName = 'Executing pre-request script' | 'Rendering request' | 'Preparin

export interface TimingStep {
stepName: StepName;
isDone: boolean;
startedAt: number;
endedAt: number;
duration?: number;
}

type TimingCallback = (steps: TimingStep[]) => void;
Expand All @@ -27,8 +26,7 @@ export function addRequestTimingRecord(
export function finishLastRequestTimingRecord(requestId: string) {
const latest = executions.get(requestId)?.at(-1);
if (latest) {
latest.isDone = true;
latest.endedAt = Date.now();
latest.duration = (Date.now() - latest.startedAt);
}
}

Expand Down
7 changes: 2 additions & 5 deletions packages/insomnia/src/ui/components/response-timer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const ResponseTimer: FunctionComponent<Props> = ({ handleCancel, activeRe
<div className='w-3/4 text-left content-center leading-8'>
<span className="leading-8">
{
record.isDone ?
record.duration ?
(<i className="fa fa-circle-check fa-2x mr-2 text-green-500" />) :
(<i className="fa fa-spinner fa-spin fa-2x mr-2" />)
}
Expand All @@ -54,10 +54,7 @@ export const ResponseTimer: FunctionComponent<Props> = ({ handleCancel, activeRe
{record.stepName}
</span>
</div>
{record.isDone ? `${((record.endedAt - record.startedAt) / 1000).toFixed(1)} s` : (<MillisecondTimer />)}
{/* <div className='w-1/4 text-right' style={{ fontVariantNumeric: 'tabular-nums' }}>
{timingToDisplay > 0 ? `${timingToDisplay.toFixed(2)}s` : '0s'}
</div> */}
{record.duration ? `${((record.duration) / 1000).toFixed(1)} s` : (<MillisecondTimer />)}
</div>
);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/insomnia/src/ui/components/tags/time-tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export const TimeTag: FC<Props> = memo(({ milliseconds, small, className, toolti
>
<Tooltip
message={<>
<div>{milliseconds.toFixed(3)} ms</div>
{steparray?.map(step => (<div key={step.stepName}>{step.stepName} {step.endedAt - step.startedAt}ms</div>))}
<div>{(milliseconds / 1000).toFixed(2)} s</div>
{steparray?.map(step => (<div key={step.stepName}>{step.stepName} {step.duration?.toFixed(2) || '?'} s</div>))}
</>}
position="bottom"
delay={tooltipDelay}
Expand Down
12 changes: 0 additions & 12 deletions packages/insomnia/src/ui/routes/request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,7 @@ export const sendAction: ActionFunction = async ({ request, params }) => {
requestId,
{
stepName: 'Executing pre-request script',
isDone: false,
startedAt: Date.now(),
endedAt: 0,
},
);

Expand All @@ -395,9 +393,7 @@ export const sendAction: ActionFunction = async ({ request, params }) => {
requestId,
{
stepName: 'Rendering request',
isDone: false,
startedAt: Date.now(),
endedAt: 0,
},
);

Expand Down Expand Up @@ -429,9 +425,7 @@ export const sendAction: ActionFunction = async ({ request, params }) => {
requestId,
{
stepName: 'Preparing and sending request',
isDone: false,
startedAt: Date.now(),
endedAt: 0,
},
);

Expand All @@ -457,9 +451,7 @@ export const sendAction: ActionFunction = async ({ request, params }) => {
requestId,
{
stepName: 'Executing after-response script',
isDone: false,
startedAt: Date.now(),
endedAt: 0,
},
);

Expand Down Expand Up @@ -548,9 +540,7 @@ export const createAndSendToMockbinAction: ActionFunction = async ({ request })
req._id,
{
stepName: 'Rendering request',
isDone: false,
startedAt: Date.now(),
endedAt: 0,
},
);

Expand All @@ -562,9 +552,7 @@ export const createAndSendToMockbinAction: ActionFunction = async ({ request })
req._id,
{
stepName: 'Preparing and sending request',
isDone: false,
startedAt: Date.now(),
endedAt: 0,
},
);

Expand Down

0 comments on commit 8a51595

Please sign in to comment.