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.
|
||||
const linesToShow = Math.ceil(Math.min(window.innerHeight, 2000) / 5);
|
||||
this.textarea.value = this.logText
|
||||
.split(/\n/g)
|
||||
.slice(0, linesToShow)
|
||||
.split(/\n/g, linesToShow)
|
||||
.concat(['', i18n('loading')])
|
||||
.join('\n');
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { z } from 'zod';
|
||||
import * as pino from 'pino';
|
||||
import { redactAll } from '../util/privacy';
|
||||
import { missingCaseError } from '../util/missingCaseError';
|
||||
|
@ -20,15 +19,40 @@ export enum LogLevel {
|
|||
|
||||
// These match [Pino's core fields][1].
|
||||
// [1]: https://getpino.io/#/?id=usage
|
||||
const logEntrySchema = z.object({
|
||||
level: z.nativeEnum(LogLevel),
|
||||
msg: z.string(),
|
||||
time: z.string().refine(value => !Number.isNaN(new Date(value).getTime())),
|
||||
});
|
||||
export type LogEntryType = z.infer<typeof logEntrySchema>;
|
||||
export type LogEntryType = Readonly<{
|
||||
level: LogLevel;
|
||||
msg: string;
|
||||
time: string;
|
||||
}>;
|
||||
|
||||
export const isLogEntry = (data: unknown): data is LogEntryType =>
|
||||
logEntrySchema.safeParse(data).success;
|
||||
// The code below is performance sensitive since it runs for > 100k log entries
|
||||
// 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 {
|
||||
switch (value) {
|
||||
|
|
Loading…
Reference in a new issue