Skip to content

Commit

Permalink
[FIX] Web Client memory leak caused by the Emoji library (#17320)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored Apr 20, 2020
1 parent 5a06e4b commit b89873f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
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

0 comments on commit b89873f

Please sign in to comment.