Skip to content

Commit

Permalink
Cache results of md5 calls
Browse files Browse the repository at this point in the history
  • Loading branch information
bajtos committed Aug 24, 2016
1 parent 33c3076 commit 91ae698
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/globalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var helper = require('./helper');
var osLocale = require('os-locale');
var MapCache = require('lodash/_MapCache');
var md5 = require('md5');
var memoize = require('lodash/memoize');
var pathUtil = require('path');
var translate = require('./translate');
var util = require('util');
Expand Down Expand Up @@ -117,9 +118,10 @@ function setDefaultLanguage(lang) {
*/
function formatMessage(path, variables, lang) {
assert(path);
var message = path;
if (helper.hashKeys(path)) path = md5(path);
if (!global.STRONGLOOP_GLB) setDefaultLanguage();
var message = path;
if (helper.hashKeys(path))
path = global.STRONGLOOP_GLB.getHash(path);
lang = lang || global.STRONGLOOP_GLB.DEFAULT_LANG;
debug('~~~ lang = %s %s %j %s', lang, path, variables, __filename);
var trailer = helper.getTrailerAfterDot(path);
Expand Down Expand Up @@ -382,6 +384,7 @@ function loadGlobalize(lang, enumerateNodeModules) {
versionG: versionG,
bundles: {},
formatters: new MapCache(),
getHash: memoize(md5),
load: Globalize.load,
locale: Globalize.locale,
loadMessages: Globalize.loadMessages,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"g11n-pipeline": "^1.2.2",
"globalize": "^1.1.0",
"htmlparser2": "^3.9.0",
"lodash": "^4.3.0",
"lodash": "^4.15.0",
"md5": "^2.0.0",
"mkdirp": "^0.5.1",
"mktmpdir": "^0.1.1",
Expand Down

0 comments on commit 91ae698

Please sign in to comment.