0

I have a table in RethinkDB consisting of 3 millions tweets. Each field has an epoch time, when it was inserted. What javascript query could I make to get quickly the tweets from the last 24 hours (roughly about 50k) sorted by keyword? I tried something below, but it is really slow.

`r.db('twitter').table('tweets')
  .group('keyword') 
  .filter((row) => {
    return row('epoch_time').gt(r.now().sub(86400)); 
  })
  .orderBy(r.desc('time'))
  .pluck('url', 'text') `
crisscross
  • 1,675
  • 2
  • 18
  • 28

1 Answers1

0

A bit late for you I imagine, but may help others who find this in their search results.

  • group('keyword') returns a reduction so won't have an 'epoch_time'
  • if you know that you only want tweet from the last 24 hours then put that filter first. There is no query optimiser in RethinkDB.
  • if performance is still an issue after that, consider putting an index on 'epoch_time' and change your filter (does a table scan) to getAll...
  • if still an issue after that, index by 'keyword'
Failing Coder
  • 646
  • 1
  • 10
  • 16
  • Thanks for your answer. I tried it without the group query, but it is still very slow. Can you give a full example how to rewrite? – crisscross Jul 10 '17 at 17:24