Santhosh has uploaded a new change for review. https://gerrit.wikimedia.org/r/129396
Change subject: WIP Redis Cache model ...................................................................... WIP Redis Cache model See https://www.mediawiki.org/wiki/Content_translation/Caching Change-Id: Id0355e995e2dbd146eefd4574bbacce6ccc8226c --- M models/DataModelManager.js 1 file changed, 31 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/96/129396/1 diff --git a/models/DataModelManager.js b/models/DataModelManager.js index 02c62ed..640ca38 100644 --- a/models/DataModelManager.js +++ b/models/DataModelManager.js @@ -33,10 +33,10 @@ PageLoader, pageloader; // TODO: refactor this - this.context.store.get( this.context.sourcePage, function ( err, data ) { - dataModelManager.dataModel = JSON.parse( data ); + this.context.store.get( this.getCacheKey() + ':segmentedContent', function ( err, data ) { + dataModelManager.dataModel.segmentedContent = data; - if ( dataModelManager.dataModel ) { + if ( data ) { // data model present in redis store dataModelManager.publish(); } else { @@ -81,18 +81,40 @@ */ CXDataModelManager.prototype.publish = function () { var dataModelManager = this, - data = JSON.stringify( dataModelManager.getDataModel() ); + key, segmentId, commandQueue, linkId, + data = dataModelManager.getDataModel(); // TODO: Make the key unique, language pair also should be considered - // TODO: Make the data model in the redis store more granular than - // a single json dump. - this.context.store.set( this.dataModel.sourcePage, data, function () { - dataModelManager.context.pub.publish( 'cx', data ); + // TODO: Rafactor to a cache manager + key = this.getCacheKey(); + commandQueue = this.context.store.multi(); + commandQueue.set( key + ':segmentedContent', data.segmentedContent ); + for ( segmentId in data.segments ) { + commandQueue.hmset( key + ':segments:' + segmentId, data.segments[ segmentId ] ); + } + for ( segmentId in data.mt ) { + commandQueue.set( key + ':mt:' + segmentId, data.mt[ segmentId ] ); + } + for ( linkId in data.links ) { + commandQueue.hmset( key + ':links:' + segmentId, data.links[ linkId ] ); + } + commandQueue.exec( function ( error ) { + if ( error ) { + throw ( error ); + } + dataModelManager.context.pub.publish( 'cx', JSON.stringify( data ) ); } ); - logger.debug( 'Sending data. Version: ' + this.dataModel.version ); + logger.debug( 'Sending data.Version: ' + this.dataModel.version ); this.incrementVersionNumber(); +}; + +/** + * Update the version number of the model + */ +CXDataModelManager.prototype.getCacheKey = function () { + return this.context.sourceLanguage + ':' + this.context.sourcePage + ':' + this.context.targetLanguage; }; /** @@ -101,7 +123,6 @@ CXDataModelManager.prototype.incrementVersionNumber = function () { this.dataModel.version += 1; }; - /** * Get the data model */ -- To view, visit https://gerrit.wikimedia.org/r/129396 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id0355e995e2dbd146eefd4574bbacce6ccc8226c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits