Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Web Client memory leak caused by the Emoji rendering #17320

Merged
merged 4 commits into from
Apr 20, 2020
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
2 changes: 1 addition & 1 deletion app/authorization/server/functions/hasPermission.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Permissions, Users, Subscriptions } from '../../../models/server/raw';
const rolesHasPermission = mem(async (permission, roles) => {
const result = await Permissions.findOne({ _id: permission, roles: { $in: roles } });
return !!result;
});
}, process.env.TEST_MODE === 'true' ? { maxAge: 0 } : undefined);

const getRoles = mem(async (uid, scope) => {
const { roles: userRoles = [] } = await Users.findOne({ _id: uid });
Expand Down
9 changes: 5 additions & 4 deletions app/emoji-emojione/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ emojione.emojioneList[':asterisk_symbol:'] = {

// fix for :+1: - had to replace all function that does its conversion: https://github.com/joypixels/emojione/blob/4.5.0/lib/js/emojione.js#L249
(function(ns) {
ns.shortnameConversionMap = mem(ns.shortnameConversionMap);
ns.unicodeCharRegex = mem(ns.unicodeCharRegex);
ns.shortnameConversionMap = mem(ns.shortnameConversionMap, { maxAge: 1000 });

ns.unicodeCharRegex = mem(ns.unicodeCharRegex, { maxAge: 1000 });

const convertShortName = mem(function(shortname) {
// the fix is basically adding this .replace(/[+]/g, '\\$&')
Expand Down Expand Up @@ -202,7 +203,7 @@ emojione.emojioneList[':asterisk_symbol:'] = {
return `<span class="emojione emojione-${ category } _${ fname }" ${ title }>${ alt }</span>`;
}
return `<img class="emojione" alt="${ alt }" ${ title } src="${ ePath }${ fname }${ ns.fileExtension }"/>`;
});
}, { maxAge: 1000 });

const convertUnicode = mem(function(entire, m1, m2, m3) {
const mappedUnicode = ns.mapUnicodeToShort();
Expand All @@ -228,7 +229,7 @@ emojione.emojioneList[':asterisk_symbol:'] = {
return `${ m2 }<span class="emojione emojione-${ category } _${ unicode }" ${ title }>${ alt }</span>`;
}
return `${ m2 }<img class="emojione" alt="${ alt }" ${ title } src="${ ePath }${ unicode }${ ns.fileExtension }"/>`;
});
}, { maxAge: 1000 });

ns.shortnameToImage = function(str) {
// replace regular shortnames first
Expand Down
45 changes: 35 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
"lru-cache": "^5.1.1",
"mailparser": "^2.4.3",
"marked": "^0.6.1",
"mem": "4.1.0",
"mem": "^6.1.0",
"meteor-node-stubs": "^1.0.0",
"mime-db": "^1.40.0",
"mime-type": "^3.0.7",
Expand Down