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

Use Sets instead of array scans and simplify hiding of invalid users when inviting #4004

Merged
merged 3 commits into from
Jan 30, 2020

Conversation

t3chguy
Copy link
Member

@t3chguy t3chguy commented Jan 30, 2020

The difference between excludedTargetIds and excludedUserIds may be lost on me :(

it was pruning out the excludedTargetIds then adding any lastSpoke users back in anyway to suggestions

Seeing so many nested loops and .includes calls hurt me deeply so I flipped things over to use ES6 Sets.

Fixes element-hq/element-web#12051

Signed-off-by: Michael Telatynski [email protected]

@t3chguy t3chguy requested a review from turt2live January 30, 2020 19:34
@turt2live
Copy link
Member

Is there a bug here or is this just cleanup?

@t3chguy
Copy link
Member Author

t3chguy commented Jan 30, 2020

As the first post says:

Fixes element-hq/element-web#12051

@@ -456,7 +453,7 @@ export default class InviteDialog extends React.PureComponent {
const events = room.getLiveTimeline().getEvents(); // timelines are most recent last
for (let i = events.length - 1; i >= Math.max(0, events.length - maxMessagesConsidered); i--) {
const ev = events[i];
if (excludedUserIds.includes(ev.getSender())) {
if (excludedTargetIds.has(ev.getSender())) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was not skipping on the members already in the room

@turt2live
Copy link
Member

I honestly don't see "Fixes XXXX" unless it is bold, sorry :(

Copy link
Member

@turt2live turt2live left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I see the benefit of sets, but this seems to work.

src/components/views/dialogs/InviteDialog.js Outdated Show resolved Hide resolved
@t3chguy
Copy link
Member Author

t3chguy commented Jan 30, 2020

Not sure I see the benefit of sets, but this seems to work.

Set has closer to O(1) opposed to O(n) lookups on the general case where the user is not to be omitted.

@t3chguy t3chguy requested a review from turt2live January 30, 2020 21:12
@turt2live
Copy link
Member

sure, but it's still just as fast. It's too small of a dataset to really make much of a difference.

@t3chguy
Copy link
Member Author

t3chguy commented Jan 30, 2020

ah its limited at 200, fair enough

@t3chguy t3chguy merged commit b98b0fe into develop Jan 30, 2020
@t3chguy t3chguy deleted the t3chguy/invite branch April 27, 2020 17:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invite to this room shouldn't suggest users who are already in the room
2 participants