mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
LogsPanel: Fix performance drop when moving logs panel in dashboard. (#35379)
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { useCallback, useMemo } from 'react';
|
||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
import { LogRows, CustomScrollbar, useTheme2 } from '@grafana/ui';
|
import { LogRows, CustomScrollbar, useTheme2 } from '@grafana/ui';
|
||||||
import { PanelProps, Field } from '@grafana/data';
|
import { PanelProps, Field } from '@grafana/data';
|
||||||
@@ -15,6 +15,22 @@ export const LogsPanel: React.FunctionComponent<LogsPanelProps> = ({
|
|||||||
title,
|
title,
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme2();
|
const theme = useTheme2();
|
||||||
|
|
||||||
|
// Important to memoize stuff here, as panel rerenders a lot for example when resizing.
|
||||||
|
const [logRows, deduplicatedRows] = useMemo(() => {
|
||||||
|
const newResults = data ? dataFrameToLogsModel(data.series, data.request?.intervalMs) : null;
|
||||||
|
const logRows = newResults?.rows || [];
|
||||||
|
const deduplicatedRows = dedupLogRows(logRows, dedupStrategy);
|
||||||
|
return [logRows, deduplicatedRows];
|
||||||
|
}, [data, dedupStrategy]);
|
||||||
|
|
||||||
|
const getFieldLinks = useCallback(
|
||||||
|
(field: Field, rowIndex: number) => {
|
||||||
|
return getFieldLinksForExplore({ field, rowIndex, range: data.timeRange });
|
||||||
|
},
|
||||||
|
[data]
|
||||||
|
);
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return (
|
return (
|
||||||
<div className="panel-empty">
|
<div className="panel-empty">
|
||||||
@@ -29,14 +45,6 @@ export const LogsPanel: React.FunctionComponent<LogsPanelProps> = ({
|
|||||||
margin-top: ${theme.spacing(!title ? 2.5 : 0)};
|
margin-top: ${theme.spacing(!title ? 2.5 : 0)};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const newResults = data ? dataFrameToLogsModel(data.series, data.request?.intervalMs) : null;
|
|
||||||
const logRows = newResults?.rows || [];
|
|
||||||
const deduplicatedRows = dedupLogRows(logRows, dedupStrategy);
|
|
||||||
|
|
||||||
const getFieldLinks = (field: Field, rowIndex: number) => {
|
|
||||||
return getFieldLinksForExplore({ field, rowIndex, range: data.timeRange });
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CustomScrollbar autoHide>
|
<CustomScrollbar autoHide>
|
||||||
<div className={spacing}>
|
<div className={spacing}>
|
||||||
@@ -44,7 +52,6 @@ export const LogsPanel: React.FunctionComponent<LogsPanelProps> = ({
|
|||||||
logRows={logRows}
|
logRows={logRows}
|
||||||
deduplicatedRows={deduplicatedRows}
|
deduplicatedRows={deduplicatedRows}
|
||||||
dedupStrategy={dedupStrategy}
|
dedupStrategy={dedupStrategy}
|
||||||
highlighterExpressions={[]}
|
|
||||||
showLabels={showLabels}
|
showLabels={showLabels}
|
||||||
showTime={showTime}
|
showTime={showTime}
|
||||||
wrapLogMessage={wrapLogMessage}
|
wrapLogMessage={wrapLogMessage}
|
||||||
|
|||||||
Reference in New Issue
Block a user