Twitter流api node.js - 缓慢流下来

问题描述:

我做了一个应用程序,可以让你搜索一个位置,然后显示一个过滤的Twitter的饲料有关的位置,问题是像'伦敦'的搜索有如此多的实时推文,以至于Feed无法正常阅读。Twitter流api node.js - 缓慢流下来

我不知道我是否应该停止并启动套接字?或者将所有推文推入前面的数组中,然后追加它们,但数组很容易变得太大。还有一些搜索会很慢,所以这不需要一直发生。

我已经建立它与节点和表达,任何思想如何应对这个数量,如果数据将不胜感激。

示例代码 - 后端

var place = [ '-122.75', '36.8', '-121.75', '37.8' ] 
    var stream = twitter.stream('statuses/filter', { locations: place, language: 'en' }) 

    stream.on('tweet', function (tweet) { 
    console.log(tweet) 
    }) 

    io.on('connect', function(socket) { 

    // this is coming from the twit module. 
    // 'tweet' is one of the events it listens to 
    stream.on('tweet', function(status) { 

    // this is our own channel we set up to to send the tweets down to the client 
    var data = {}; 
    data.name = status.user.name; 
    data.screen_name = status.user.screen_name; 
    data.text = status.text; 
    data.user_profile_image = status.user.profile_image_url; 

    socket.emit('statuses', data); 
    }); 
}); 

你可以尝试使用readable.pause()函数 - 这里更多的参考吧:https://nodejs.org/api/stream.html#stream_readable_pause

基本上你可以暂停与.pause流(),当你可以再次阅读,你可以调用.resume()。

另一个想法是以某种方式过滤数据。当你放慢速度时,一小时后你会比“主流”晚一个小时。