Joined May 2011
·

Peter Vandenabeele

self employed
·
Belgium
·
·
·

Posted to A better way to tail logs over 1 year ago

Other way is to start less -R (the -R solves problems with colors) and then press F for the "tail" behavior inside less (and control-C to get out of the tail, gg to go to start, and G to go to complete EOF).

I have no real opinion on [0] ... (I presume it first reifies the relationship (without the order by id) and then applies the [0] to the first and single one of that reified list; that amounts to pick_a_random_one).

So, all these amounts to the fast pick_a_random_one

  • Foobar.where(x: 'y').limit(1).to_a[0]
  • Foobar.where(x: 'y').limit(1).to_set[0]
  • Foobar.where(x: 'y').limit(1).to_a.first

What matters is if the .first operates on the
ActiveRecord_Relation before the reification
(the introduces the default order by :id), or if
the first (or [0]) operate after the reification,
on an Array of Set then.

I prefer the current behavior where .first is not longer the same as .randompickone (strangely enough, .last always had the order by id built in, .first only since Rails 4, http://api.rubyonrails.org/classes/ActiveRecord/FinderMethods.html#method-i-first)

For the "give me one, I don't care which one", that would be .take or .take(1)
http://api.rubyonrails.org/classes/ActiveRecord/FinderMethods.html#method-i-take

Yes, this works. Thanks !

Achievements
79 Karma
0 Total ProTip Views