Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Remove rateLimitedFunc #6300

Merged
merged 2 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore.errorfiles
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ src/Markdown.js
src/NodeAnimator.js
src/components/structures/RoomDirectory.js
src/components/views/rooms/MemberList.js
src/ratelimitedfunc.js
src/utils/DMRoomMap.js
src/utils/MultiInviter.js
test/components/structures/MessagePanel-test.js
Expand Down
11 changes: 5 additions & 6 deletions src/components/structures/RightPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";

import dis from '../../dispatcher/dispatcher';
import RateLimitedFunc from '../../ratelimitedfunc';
import GroupStore from '../../stores/GroupStore';
import {
RIGHT_PANEL_PHASES_NO_ARGS,
Expand All @@ -48,6 +47,7 @@ import FilePanel from "./FilePanel";
import NotificationPanel from "./NotificationPanel";
import ResizeNotifier from "../../utils/ResizeNotifier";
import PinnedMessagesCard from "../views/right_panel/PinnedMessagesCard";
import { throttle } from 'lodash';

interface IProps {
room?: Room; // if showing panels for a given room, this is set
Expand All @@ -73,7 +73,6 @@ interface IState {
export default class RightPanel extends React.Component<IProps, IState> {
static contextType = MatrixClientContext;

private readonly delayedUpdate: RateLimitedFunc;
private dispatcherRef: string;

constructor(props, context) {
Expand All @@ -84,12 +83,12 @@ export default class RightPanel extends React.Component<IProps, IState> {
isUserPrivilegedInGroup: null,
member: this.getUserForPanel(),
};

this.delayedUpdate = new RateLimitedFunc(() => {
this.forceUpdate();
}, 500);
}

private readonly delayedUpdate = throttle((): void => {
this.forceUpdate();
}, 500, { leading: true, trailing: true });

// Helper function to split out the logic for getPhaseFromProps() and the constructor
// as both are called at the same time in the constructor.
private getUserForPanel() {
Expand Down
12 changes: 6 additions & 6 deletions src/components/structures/RoomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import Modal from '../../Modal';
import * as sdk from '../../index';
import CallHandler, { PlaceCallType } from '../../CallHandler';
import dis from '../../dispatcher/dispatcher';
import rateLimitedFunc from '../../ratelimitedfunc';
import * as Rooms from '../../Rooms';
import eventSearch, { searchPagination } from '../../Searching';
import MainSplit from './MainSplit';
Expand Down Expand Up @@ -82,6 +81,7 @@ import { IOpts } from "../../createRoom";
import { replaceableComponent } from "../../utils/replaceableComponent";
import UIStore from "../../stores/UIStore";
import EditorStateTransfer from "../../utils/EditorStateTransfer";
import { throttle } from "lodash";

const DEBUG = false;
let debuglog = function(msg: string) {};
Expand Down Expand Up @@ -675,8 +675,8 @@ export default class RoomView extends React.Component<IProps, IState> {
);
}

// cancel any pending calls to the rate_limited_funcs
this.updateRoomMembers.cancelPendingCall();
// cancel any pending calls to the throttled updated
this.updateRoomMembers.cancel();

for (const watcher of this.settingWatchers) {
SettingsStore.unwatchSetting(watcher);
Expand Down Expand Up @@ -1092,7 +1092,7 @@ export default class RoomView extends React.Component<IProps, IState> {
return;
}

this.updateRoomMembers(member);
this.updateRoomMembers();
};

private onMyMembership = (room: Room, membership: string, oldMembership: string) => {
Expand All @@ -1114,10 +1114,10 @@ export default class RoomView extends React.Component<IProps, IState> {
}

// rate limited because a power level change will emit an event for every member in the room.
private updateRoomMembers = rateLimitedFunc(() => {
private updateRoomMembers = throttle(() => {
this.updateDMState();
this.updateE2EStatus(this.state.room);
}, 500);
}, 500, { leading: true, trailing: true });

private checkDesktopNotifications() {
const memberCount = this.state.room.getJoinedMemberCount() + this.state.room.getInvitedMemberCount();
Expand Down
6 changes: 3 additions & 3 deletions src/components/views/rooms/AuxPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import { Room } from 'matrix-js-sdk/src/models/room';

import { MatrixClientPeg } from "../../../MatrixClientPeg";
import AppsDrawer from './AppsDrawer';
import RateLimitedFunc from '../../../ratelimitedfunc';
import SettingsStore from "../../../settings/SettingsStore";
import AutoHideScrollbar from "../../structures/AutoHideScrollbar";
import { UIFeature } from "../../../settings/UIFeature";
import ResizeNotifier from "../../../utils/ResizeNotifier";
import CallViewForRoom from '../voip/CallViewForRoom';
import { objectHasDiff } from "../../../utils/objects";
import { replaceableComponent } from "../../../utils/replaceableComponent";
import { throttle } from 'lodash';

interface IProps {
// js-sdk room object
Expand Down Expand Up @@ -99,9 +99,9 @@ export default class AuxPanel extends React.Component<IProps, IState> {
}
}

private rateLimitedUpdate = new RateLimitedFunc(() => {
private rateLimitedUpdate = throttle(() => {
this.setState({ counters: this.computeCounters() });
}, 500);
}, 500, { leading: true, trailing: true });

private computeCounters() {
const counters = [];
Expand Down
8 changes: 4 additions & 4 deletions src/components/views/rooms/MemberList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { _t } from '../../../languageHandler';
import SdkConfig from '../../../SdkConfig';
import dis from '../../../dispatcher/dispatcher';
import { isValid3pidInvite } from "../../../RoomInvite";
import rateLimitedFunction from "../../../ratelimitedfunc";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import { CommunityPrototypeStore } from "../../../stores/CommunityPrototypeStore";
import BaseCard from "../right_panel/BaseCard";
Expand All @@ -43,6 +42,7 @@ import AccessibleButton from '../elements/AccessibleButton';
import EntityTile from "./EntityTile";
import MemberTile from "./MemberTile";
import BaseAvatar from '../avatars/BaseAvatar';
import { throttle } from 'lodash';

const INITIAL_LOAD_NUM_MEMBERS = 30;
const INITIAL_LOAD_NUM_INVITED = 5;
Expand Down Expand Up @@ -133,7 +133,7 @@ export default class MemberList extends React.Component<IProps, IState> {
}

// cancel any pending calls to the rate_limited_funcs
this.updateList.cancelPendingCall();
this.updateList.cancel();
}

/**
Expand Down Expand Up @@ -237,9 +237,9 @@ export default class MemberList extends React.Component<IProps, IState> {
if (this.canInvite !== this.state.canInvite) this.setState({ canInvite: this.canInvite });
};

private updateList = rateLimitedFunction(() => {
private updateList = throttle(() => {
this.updateListNow();
}, 500);
}, 500, { leading: true, trailing: true });

private updateListNow(): void {
const members = this.roomMembers();
Expand Down
7 changes: 3 additions & 4 deletions src/components/views/rooms/RoomHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import PropTypes from 'prop-types';
import classNames from 'classnames';
import { _t } from '../../../languageHandler';
import { MatrixClientPeg } from '../../../MatrixClientPeg';
import RateLimitedFunc from '../../../ratelimitedfunc';

import SettingsStore from "../../../settings/SettingsStore";
import RoomHeaderButtons from '../right_panel/RoomHeaderButtons';
Expand All @@ -31,6 +30,7 @@ import RoomTopic from "../elements/RoomTopic";
import RoomName from "../elements/RoomName";
import { PlaceCallType } from "../../../CallHandler";
import { replaceableComponent } from "../../../utils/replaceableComponent";
import { throttle } from 'lodash';

@replaceableComponent("views.rooms.RoomHeader")
export default class RoomHeader extends React.Component {
Expand Down Expand Up @@ -73,10 +73,9 @@ export default class RoomHeader extends React.Component {
this._rateLimitedUpdate();
};

_rateLimitedUpdate = new RateLimitedFunc(function() {
/* eslint-disable @babel/no-invalid-this */
_rateLimitedUpdate = throttle(() => {
this.forceUpdate();
}, 500);
}, 500, { leading: true, trailing: true });

render() {
let searchStatus = null;
Expand Down
8 changes: 4 additions & 4 deletions src/components/views/rooms/SendMessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import Modal from '../../../Modal';
import { _t, _td } from '../../../languageHandler';
import ContentMessages from '../../../ContentMessages';
import MatrixClientContext from "../../../contexts/MatrixClientContext";
import RateLimitedFunc from '../../../ratelimitedfunc';
import { Action } from "../../../dispatcher/actions";
import { containsEmoji } from "../../../effects/utils";
import { CHAT_EFFECTS } from '../../../effects';
Expand All @@ -53,6 +52,7 @@ import { Room } from 'matrix-js-sdk/src/models/room';
import ErrorDialog from "../dialogs/ErrorDialog";
import QuestionDialog from "../dialogs/QuestionDialog";
import { ActionPayload } from "../../../dispatcher/payloads";
import { DebouncedFunc, throttle } from 'lodash';

function addReplyToMessageContent(
content: IContent,
Expand Down Expand Up @@ -138,7 +138,7 @@ export default class SendMessageComposer extends React.Component<IProps> {
static contextType = MatrixClientContext;
context!: React.ContextType<typeof MatrixClientContext>;

private readonly prepareToEncrypt?: RateLimitedFunc;
private readonly prepareToEncrypt?: DebouncedFunc<() => void>;
private readonly editorRef = createRef<BasicMessageComposer>();
private model: EditorModel = null;
private currentlyComposedEditorState: SerializedPart[] = null;
Expand All @@ -149,9 +149,9 @@ export default class SendMessageComposer extends React.Component<IProps> {
super(props);
this.context = context; // otherwise React will only set it prior to render due to type def above
if (this.context.isCryptoEnabled() && this.context.isRoomEncrypted(this.props.room.roomId)) {
this.prepareToEncrypt = new RateLimitedFunc(() => {
this.prepareToEncrypt = throttle(() => {
this.context.prepareToEncrypt(this.props.room);
}, 60000);
}, 60000, { leading: true, trailing: false });
}

window.addEventListener("beforeunload", this.saveStoredEditorState);
Expand Down
47 changes: 0 additions & 47 deletions src/ratelimitedfunc.js

This file was deleted.