Skip to content

Commit

Permalink
Reuse query object if its value persists
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Fernández Gómez committed Jun 22, 2021
1 parent 28142c9 commit cd5dd40
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions x-pack/plugins/infra/public/containers/logs/log_stream/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* 2.0.
*/

import { isEqual } from 'lodash';
import createContainer from 'constate';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useCallback, useEffect, useMemo, useState, useRef } from 'react';
import usePrevious from 'react-use/lib/usePrevious';
import useSetState from 'react-use/lib/useSetState';
import { esQuery } from '../../../../../../../src/plugins/data/public';
Expand Down Expand Up @@ -65,6 +66,12 @@ export function useLogStream({
const prevStartTimestamp = usePrevious(startTimestamp);
const prevEndTimestamp = usePrevious(endTimestamp);

const cachedQuery = useRef(query);

if (!isEqual(query, cachedQuery)) {
cachedQuery.current = query;
}

useEffect(() => {
if (prevStartTimestamp && prevStartTimestamp > startTimestamp) {
setState({ hasMoreBefore: true });
Expand All @@ -82,10 +89,10 @@ export function useLogStream({
sourceId,
startTimestamp,
endTimestamp,
query,
query: cachedQuery.current,
columnOverrides: columns,
}),
[columns, endTimestamp, query, sourceId, startTimestamp]
[columns, endTimestamp, cachedQuery, sourceId, startTimestamp]
);

const {
Expand Down

0 comments on commit cd5dd40

Please sign in to comment.