@@ -6,6 +6,9 @@ var waterfall = require('async/waterfall');
66var productSearchService = require ( '../services/productSearchService' ) ;
77var redisClient = require ( '../libraries/redis-client' ) ;
88var md5 = require ( 'blueimp-md5' ) ;
9+ var RedisQueue = require ( "simple-redis-queue" ) ;
10+
11+ var push_queue = new RedisQueue ( redisClient . getClient ( ) ) ;
912
1013/* GET products listing. */
1114router . get ( '/' , function ( req , res , next ) {
@@ -80,32 +83,15 @@ router.post('/new', function(req, res, next) {
8083 } )
8184 } ) ;
8285 } ,
83- function ( result , waterfallCallback ) { // Getting Product Category From DB (Preparing for Elasticsearch)
84- categoryService . getProductCategories ( result . insertId , function ( err , productCategories ) {
85- if ( err ) { }
86- result . productCategories = productCategories ;
87- waterfallCallback ( false , result ) ;
88- } ) ;
89- } ,
90- function ( result , waterfallCallback ) { // Getting Product Data From MySQL DB (Preparing for Elasticsearch)
91- productService . getRecord ( result . insertId , function ( err , product ) {
92- if ( err ) { }
93- result . product = product ;
86+ function ( result , waterfallCallback ) {
87+ push_queue . push ( 'product_updates' , { 'action' :'insert' , 'productId' : result . insertId } , function ( err , res ) {
9488 waterfallCallback ( false , result ) ;
9589 } ) ;
96- } ,
97- function ( result , waterfallCallback ) { // Saving Product to Elasticsearch
98- var product = result . product ;
99- product . categories = result . productCategories ;
100-
101- productSearchService . insert ( product , function ( ) {
102- waterfallCallback ( false , product ) ;
103- } ) ;
10490 }
10591 ] ,
106- function ( err , product ) {
92+ function ( err , result ) {
10793 if ( err ) { }
108- res . redirect ( '/product/id/' + product . id ) ;
94+ res . redirect ( '/product/id/' + result . insertId ) ;
10995 }
11096 ) ;
11197} ) ;
@@ -122,8 +108,7 @@ router.get('/:id/delete', function(req, res, next) {
122108 } ) ;
123109 } ,
124110 function ( waterfallCallback ) {
125- productSearchService . delete ( params . id , function ( err , result ) {
126- //TODO: check error status
111+ push_queue . push ( 'product_updates' , { 'action' :'delete' , 'productId' : params . id } , function ( err , res ) {
127112 waterfallCallback ( false ) ;
128113 } ) ;
129114 }
@@ -210,33 +195,15 @@ router.post('/:id/edit', function(req, res, next) {
210195 } )
211196 } ) ;
212197 } ,
213- function ( waterfallCallback ) { // Getting Product Categories Data from MySQL (Preparing for Elasticsearch)
214- var result = { } ;
215- categoryService . getProductCategories ( params . id , function ( err , productCategories ) {
216- if ( err ) { }
217- result . productCategories = productCategories ;
218- waterfallCallback ( false , result ) ;
219- } ) ;
220- } ,
221- function ( result , waterfallCallback ) { // Getting Product Data from MySQL (Preparing for Elasticsearch)
222- productService . getRecord ( params . id , function ( err , product ) {
223- if ( err ) { }
224- result . product = product ;
225- waterfallCallback ( false , result ) ;
226- } ) ;
227- } ,
228- function ( result , waterfallCallback ) { // Saving Data to Elasticsearch
229- var product = result . product ;
230- product . categories = result . productCategories ;
231-
232- productSearchService . insert ( product , function ( ) {
233- waterfallCallback ( false , product ) ;
198+ function ( waterfallCallback ) {
199+ push_queue . push ( 'product_updates' , { 'action' :'update' , 'productId' : queryParams . id } , function ( err , res ) {
200+ waterfallCallback ( false ) ;
234201 } ) ;
235202 }
236203 ] ,
237204 function ( err , product ) {
238205 if ( err ) { }
239- res . redirect ( '/product/id/' + product . id ) ;
206+ res . redirect ( '/product/id/' + queryParams . id ) ;
240207 return ;
241208 }
242209 ) ;
0 commit comments