Fix performance of debug logs view
This commit is contained in:
parent
ff94050c0a
commit
287abd241d
2 changed files with 34 additions and 11 deletions
|
@ -111,8 +111,7 @@
|
||||||
// we need to scroll, but not so many that things get slow.
|
// we need to scroll, but not so many that things get slow.
|
||||||
const linesToShow = Math.ceil(Math.min(window.innerHeight, 2000) / 5);
|
const linesToShow = Math.ceil(Math.min(window.innerHeight, 2000) / 5);
|
||||||
this.textarea.value = this.logText
|
this.textarea.value = this.logText
|
||||||
.split(/\n/g)
|
.split(/\n/g, linesToShow)
|
||||||
.slice(0, linesToShow)
|
|
||||||
.concat(['', i18n('loading')])
|
.concat(['', i18n('loading')])
|
||||||
.join('\n');
|
.join('\n');
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
// Copyright 2021 Signal Messenger, LLC
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import { z } from 'zod';
|
|
||||||
import * as pino from 'pino';
|
import * as pino from 'pino';
|
||||||
import { redactAll } from '../util/privacy';
|
import { redactAll } from '../util/privacy';
|
||||||
import { missingCaseError } from '../util/missingCaseError';
|
import { missingCaseError } from '../util/missingCaseError';
|
||||||
|
@ -20,15 +19,40 @@ export enum LogLevel {
|
||||||
|
|
||||||
// These match [Pino's core fields][1].
|
// These match [Pino's core fields][1].
|
||||||
// [1]: https://getpino.io/#/?id=usage
|
// [1]: https://getpino.io/#/?id=usage
|
||||||
const logEntrySchema = z.object({
|
export type LogEntryType = Readonly<{
|
||||||
level: z.nativeEnum(LogLevel),
|
level: LogLevel;
|
||||||
msg: z.string(),
|
msg: string;
|
||||||
time: z.string().refine(value => !Number.isNaN(new Date(value).getTime())),
|
time: string;
|
||||||
});
|
}>;
|
||||||
export type LogEntryType = z.infer<typeof logEntrySchema>;
|
|
||||||
|
|
||||||
export const isLogEntry = (data: unknown): data is LogEntryType =>
|
// The code below is performance sensitive since it runs for > 100k log entries
|
||||||
logEntrySchema.safeParse(data).success;
|
// whenever we want to send the debug log. We can't use `zod` because it clones
|
||||||
|
// the data on successful parse and ruins the performance.
|
||||||
|
export const isLogEntry = (data: unknown): data is LogEntryType => {
|
||||||
|
if (data === null || typeof data !== 'object') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { level, msg, time } = data as Partial<LogEntryType>;
|
||||||
|
|
||||||
|
if (typeof level !== 'number') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!LogLevel[level]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof msg !== 'string') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof time !== 'string') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !Number.isNaN(new Date(time).getTime());
|
||||||
|
};
|
||||||
|
|
||||||
export function getLogLevelString(value: LogLevel): pino.Level {
|
export function getLogLevelString(value: LogLevel): pino.Level {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
|
|
Loading…
Reference in a new issue