diff --git a/lib/components/dictionary.js b/lib/components/dictionary.js index 725e017f2..58fd6b339 100644 --- a/lib/components/dictionary.js +++ b/lib/components/dictionary.js @@ -3,6 +3,7 @@ var path = require('path'); var utils = require('../util/utils'); var Loader = require('pomelo-loader'); var pathUtil = require('../util/pathUtil'); +var crypto = require('crypto'); module.exports = function(app, opts) { return new Component(app, opts); @@ -13,6 +14,7 @@ var Component = function(app, opts) { this.dict = {}; this.abbrs = {}; this.userDicPath = null; + this.version = ""; //Set user dictionary var p = path.join(app.getBase(), '/config/dictionary.json'); @@ -74,6 +76,9 @@ pro.start = function(cb) { abbr++; } } + + this.version = crypto.createHash('md5').update(JSON.stringify(this.dict)).digest('hex'); + utils.invokeCallback(cb); }; @@ -83,4 +88,8 @@ pro.getDict = function() { pro.getAbbrs = function() { return this.abbrs; -}; \ No newline at end of file +}; + +pro.getVersion = function() { + return this.version; +}; diff --git a/lib/connectors/commands/handshake.js b/lib/connectors/commands/handshake.js index 7b3a9b1f6..7eca68b90 100644 --- a/lib/connectors/commands/handshake.js +++ b/lib/connectors/commands/handshake.js @@ -44,7 +44,11 @@ Command.prototype.handle = function(socket, msg) { }; if(this.useDict) { - opts.dict = pomelo.app.components.__dictionary__.getDict(); + var dictVersion = pomelo.app.components.__dictionary__.getVersion(); + if(!msg.sys.dictVersion || msg.sys.dictVersion !== dictVersion){ + opts.dict = pomelo.app.components.__dictionary__.getDict(); + opts.dict.version = dictVersion; + } } if(this.useProtobuf) {