简体   繁体   English

Twitter流API节点-降低流速度

[英]Twitter streaming api node.js - Slow the stream down

I'm making an app that allows you to search a location then shows a filtered twitter feed relating to the location, the problem is on a search like 'London' there are so many realtime tweets that the feed moves so quickly that you cant read them. 我正在制作一个应用程序,允许您搜索位置,然后显示与该位置相关的已过滤Twitter提要,问题出在“伦敦”之类的搜索中,实时推文太多,提要移动得很快,以至于您无法阅读他们。

I don't know if I should stop and start the socket? 我不知道是否应该停止并启动套接字? Or push all the tweets into an array on the front then append them, but the array could quite easily get too big. 或将所有tweet推入前面的数组中,然后附加它们,但是数组很容易变得太大。 Also some searches will be really slow so this need not happen all the time. 另外,某些搜索的速度实际上会很慢,因此不必始终如此。

I have built it with node and express, any thought of how to cope with this amount if data would be appreciated. 我已经用node构建了它,并表达了任何想法,如果可以理解数据,该如何处理这个数量。

Example code - Backend 示例代码-后端

    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);
  });
});

You could try using readable.pause() function - here more reference to it: https://nodejs.org/api/stream.html#stream_readable_pause 您可以尝试使用可读.pause()函数-此处有更多参考: https : //nodejs.org/api/stream.html#stream_visible_pause

Basically you can pause the stream with .pause() and when you're able to read again, you can call .resume(). 基本上,您可以使用.pause()暂停流,当您能够再次阅读时,可以调用.resume()。

Another idea would be filtering the data somehow. 另一个想法是以某种方式过滤数据。 When you slow it down, after an hour you will be an hour behind the "main stream". 当您放慢速度时,一个小时后,您将比“主流”落后一个小时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM