Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet][Logs UI] Prevent double loading of entries in <LogStream /> component. #102980

Merged
merged 3 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Read more at https://github.com/elastic/kibana/blob/master/src/plugins/kibana_re

const {
derivedIndexPattern,
isLoadingSourceConfiguration,
isLoading: isLoadingSource,
loadSource,
sourceConfiguration,
} = useLogSource({
Expand All @@ -138,7 +138,7 @@ Read more at https://github.com/elastic/kibana/blob/master/src/plugins/kibana_re
hasMoreAfter,
hasMoreBefore,
isLoadingMore,
isReloading,
isReloading: isLoadingEntries,
} = useLogStream({
sourceId,
startTimestamp,
Expand Down Expand Up @@ -198,7 +198,7 @@ Read more at https://github.com/elastic/kibana/blob/master/src/plugins/kibana_re
items={streamItems}
scale="medium"
wrap={true}
isReloading={isLoadingSourceConfiguration || isReloading}
isReloading={isLoadingSource || isLoadingEntries}
isLoadingMore={isLoadingMore}
hasMoreBeforeStart={hasMoreBefore}
hasMoreAfterEnd={hasMoreAfter}
Expand Down
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