即使在javascript中保存了它的副本,数据也是空的(data is empty even after saving a copy of it in javascript)
var cacheData = JSON.stringify(data);
this.getTwitterSearch(data, options);
cache.setex(query, cfg.cache.news.twitter, cacheData, function(){
c.log('set cache', query, cacheData);
});
如果我注释掉这个this.getTwitterSearch一切正常。 怎么会这样? 我不知道该函数是如何使cacheData空的。
这是this.getTwitterSearch :
News.prototype.getTwitterSearch = function getTwitterSearch(data, options){ var statuses = data.statuses , items = []; c.log('statuses', statuses); _.each(statuses, function(d){ var item = this.getTwitterItem(query, d); if ( item ) { items.push(item); } }.bind(this)); //recent items since last poll if ( options.since_id ) { if ( items.length ) { this.sock.emit('twitter:new', { items: items }); } } else { //initial payload c.log('twitter:items', items.length); if ( items.length ) { this.sock.emit('twitter:items', { items: items }); } } c.log('items', items.length); //TODO set cache items //save the last id to use when fetching new items on next poll. this.lastId = items.length && items[0].id || this.lastId; }; var cacheData = JSON.stringify(data); this.getTwitterSearch(data, options); cache.setex(query, cfg.cache.news.twitter, cacheData, function(){ c.log('set cache', query, cacheData); });If I comment out this.getTwitterSearch everything works fine. How can this be? I don't see how its possible that the function is making cacheData empty.
Here is this.getTwitterSearch:
News.prototype.getTwitterSearch = function getTwitterSearch(data, options){ var statuses = data.statuses , items = []; c.log('statuses', statuses); _.each(statuses, function(d){ var item = this.getTwitterItem(query, d); if ( item ) { items.push(item); } }.bind(this)); //recent items since last poll if ( options.since_id ) { if ( items.length ) { this.sock.emit('twitter:new', { items: items }); } } else { //initial payload c.log('twitter:items', items.length); if ( items.length ) { this.sock.emit('twitter:items', { items: items }); } } c.log('items', items.length); //TODO set cache items //save the last id to use when fetching new items on next poll. this.lastId = items.length && items[0].id || this.lastId; };最满意答案
我在this.getTwitterItem(query, d);遇到错误this.getTwitterItem(query, d); 它需要将query参数传递给它。 否则错误被抛到twit.search回调中,我把它作为数据读取,而不是错误。
I had an error in this.getTwitterItem(query, d); it need the query parameter to be passed to it. Otherwise the error was being thrown to the twit.search callback and I was reading it as data, not an error.
更多推荐
发布评论