Avoid looking up settings during timeline rendering (#8313)

* Avoid showHiddenEventsInTimeline lookups

* Avoid MSC3531 feature lookups

* Test that showHiddenEventsInTimeline doesn't get looked up while
rendering

* Fix code review nits

Co-authored-by: Travis Ralston <travisr@matrix.org>
This commit is contained in:
Robin 2022-04-14 19:23:22 -04:00 committed by GitHub
parent f27386ec37
commit 7335b35fbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 120 additions and 54 deletions

View file

@ -25,7 +25,7 @@ import { haveRendererForEvent, JitsiEventFactory, JSONEventFactory, pickFactory
import { MatrixClientPeg } from "../MatrixClientPeg";
import { getMessageModerationState, MessageModerationState } from "./EventUtils";
export function getEventDisplayInfo(mxEvent: MatrixEvent, hideEvent?: boolean): {
export function getEventDisplayInfo(mxEvent: MatrixEvent, showHiddenEvents: boolean, hideEvent?: boolean): {
isInfoMessage: boolean;
hasRenderer: boolean;
isBubbleMessage: boolean;
@ -52,7 +52,7 @@ export function getEventDisplayInfo(mxEvent: MatrixEvent, hideEvent?: boolean):
}
// TODO: Thread a MatrixClient through to here
let factory = pickFactory(mxEvent, MatrixClientPeg.get());
let factory = pickFactory(mxEvent, MatrixClientPeg.get(), showHiddenEvents);
// Info messages are basically information about commands processed on a room
let isBubbleMessage = (
@ -92,11 +92,11 @@ export function getEventDisplayInfo(mxEvent: MatrixEvent, hideEvent?: boolean):
// source tile when there's no regular tile for an event and also for
// replace relations (which otherwise would display as a confusing
// duplicate of the thing they are replacing).
if (hideEvent || !haveRendererForEvent(mxEvent)) {
if (hideEvent || !haveRendererForEvent(mxEvent, showHiddenEvents)) {
// forcefully ask for a factory for a hidden event (hidden event
// setting is checked internally)
// TODO: Thread a MatrixClient through to here
factory = pickFactory(mxEvent, MatrixClientPeg.get(), true);
factory = pickFactory(mxEvent, MatrixClientPeg.get(), showHiddenEvents, true);
if (factory === JSONEventFactory) {
isBubbleMessage = false;
// Reuse info message avatar and sender profile styling

View file

@ -151,6 +151,16 @@ export enum MessageModerationState {
SEE_THROUGH_FOR_CURRENT_USER = "SEE_THROUGH_FOR_CURRENT_USER",
}
// This is lazily initialized and cached since getMessageModerationState needs it,
// and is called on timeline rendering hot-paths
let msc3531Enabled: boolean | null = null;
const getMsc3531Enabled = (): boolean => {
if (msc3531Enabled === null) {
msc3531Enabled = SettingsStore.getValue("feature_msc3531_hide_messages_pending_moderation");
}
return msc3531Enabled;
};
/**
* Determine whether a message should be displayed as hidden pending moderation.
*
@ -160,7 +170,7 @@ export enum MessageModerationState {
export function getMessageModerationState(mxEvent: MatrixEvent, client?: MatrixClient): MessageModerationState {
client = client ?? MatrixClientPeg.get(); // because param defaults don't do the correct thing
if (!SettingsStore.getValue("feature_msc3531_hide_messages_pending_moderation")) {
if (!getMsc3531Enabled()) {
return MessageModerationState.VISIBLE_FOR_ALL;
}
const visibility = mxEvent.messageVisibility();

View file

@ -407,7 +407,7 @@ export default class HTMLExporter extends Exporter {
total: events.length,
}), false, true);
if (this.cancelled) return this.cleanUp();
if (!haveRendererForEvent(event)) continue;
if (!haveRendererForEvent(event, false)) continue;
content += this.needsDateSeparator(event, prevEvent) ? this.getDateSeparator(event) : "";
const shouldBeJoined = !this.needsDateSeparator(event, prevEvent) &&

View file

@ -85,7 +85,7 @@ export default class JSONExporter extends Exporter {
total: events.length,
}), false, true);
if (this.cancelled) return this.cleanUp();
if (!haveRendererForEvent(event)) continue;
if (!haveRendererForEvent(event, false)) continue;
this.messages.push(await this.getJSONString(event));
}
return this.createJSONString();

View file

@ -112,7 +112,7 @@ export default class PlainTextExporter extends Exporter {
total: events.length,
}), false, true);
if (this.cancelled) return this.cleanUp();
if (!haveRendererForEvent(event)) continue;
if (!haveRendererForEvent(event, false)) continue;
const textForEvent = await this.plainTextForEvent(event);
content += textForEvent && `${new Date(event.getTs()).toLocaleString()} - ${textForEvent}\n`;
}