mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
Log Row: memoize row processing (#77716)
* LogRow: memoize row processing * Rename method
This commit is contained in:
parent
5e7f6e8699
commit
7e1110f1f9
@ -1,5 +1,6 @@
|
||||
import { cx } from '@emotion/css';
|
||||
import { debounce } from 'lodash';
|
||||
import memoizeOne from 'memoize-one';
|
||||
import React, { PureComponent } from 'react';
|
||||
|
||||
import { Field, LinkModel, LogRowModel, LogsSortOrder, dateTimeFormat, CoreApp, DataFrame } from '@grafana/data';
|
||||
@ -157,6 +158,12 @@ class UnThemedLogRow extends PureComponent<Props, State> {
|
||||
}
|
||||
};
|
||||
|
||||
escapeRow = memoizeOne((row: LogRowModel, forceEscape: boolean | undefined) => {
|
||||
return row.hasUnescapedContent && forceEscape
|
||||
? { ...row, entry: escapeUnescapedString(row.entry), raw: escapeUnescapedString(row.raw) }
|
||||
: row;
|
||||
});
|
||||
|
||||
render() {
|
||||
const {
|
||||
getRows,
|
||||
@ -191,10 +198,7 @@ class UnThemedLogRow extends PureComponent<Props, State> {
|
||||
[styles.highlightBackground]: permalinked && !this.state.showDetails,
|
||||
});
|
||||
|
||||
const processedRow =
|
||||
row.hasUnescapedContent && forceEscape
|
||||
? { ...row, entry: escapeUnescapedString(row.entry), raw: escapeUnescapedString(row.raw) }
|
||||
: row;
|
||||
const processedRow = this.escapeRow(row, forceEscape);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -14,6 +14,7 @@ import {
|
||||
calculateLogsLabelStats,
|
||||
calculateStats,
|
||||
checkLogsError,
|
||||
escapeUnescapedString,
|
||||
getLogLevel,
|
||||
getLogLevelFromKey,
|
||||
getLogsVolumeMaximumRange,
|
||||
@ -469,3 +470,12 @@ describe('getLogsVolumeDimensions', () => {
|
||||
expect(maximumRange).toEqual({ from: 5, to: 25 });
|
||||
});
|
||||
});
|
||||
|
||||
describe('escapeUnescapedString', () => {
|
||||
it('does not modify strings without unescaped characters', () => {
|
||||
expect(escapeUnescapedString('a simple string')).toBe('a simple string');
|
||||
});
|
||||
it('escapes unescaped strings', () => {
|
||||
expect(escapeUnescapedString(`\\r\\n|\\n|\\t|\\r`)).toBe(`\n|\n|\t|\n`);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user