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

Commit

Permalink
Merge pull request #572 from qiankanglai/dict-version
Browse files Browse the repository at this point in the history
dictVersion
  • Loading branch information
xiecc committed Jul 28, 2014
2 parents 60c2b0a + 73fb6e1 commit 6e66ada
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/components/dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');
Expand Down Expand Up @@ -74,6 +76,9 @@ pro.start = function(cb) {
abbr++;
}
}

this.version = crypto.createHash('md5').update(JSON.stringify(this.dict)).digest('hex');

utils.invokeCallback(cb);
};

Expand All @@ -83,4 +88,8 @@ pro.getDict = function() {

pro.getAbbrs = function() {
return this.abbrs;
};
};

pro.getVersion = function() {
return this.version;
};
6 changes: 5 additions & 1 deletion lib/connectors/commands/handshake.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6e66ada

Please sign in to comment.