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

dictVersion #572

Merged
merged 1 commit into from
Jul 28, 2014
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
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