DEV Community

Cover image for The most performed RANDOM querying on Rails!
Ivan Marynych
Ivan Marynych

Posted on

The most performed RANDOM querying on Rails!

๐ŸŒŸ Prepare to have your mind blown by the Unbelievable Performance Gem! ๐ŸŒŸ

Are you tired of slow random record retrieval in your Rails applications? Say goodbye to sluggish queries and hello to lightning-fast performance! Our gem is here to revolutionize the way you fetch random records, delivering results that will leave you speechless.

๐Ÿ”ฅ Experience the future of speed and efficiency as our gem seamlessly integrates into your codebase. With near-instantaneous responses, you can elevate your user experience to new heights.

๐Ÿ’ช Join the ranks of developers who are already witnessing jaw-dropping results. Don't miss out on this game-changing gem that's setting new performance standards in the Rails community.

Ready to ignite your Rails application? Visit our repo to learn more about the Unbelievable Performance Gem and be part of the performance revolution today! ๐Ÿš€๐Ÿ’Ž

GitHub logo the-rubies-way / random-rails

The most performed gem to get random record you ever seen! Available for Ruby on Rails with PostgreSQL right now!

lint test Listed on OpenSource-Heroes.com

RandomRails

The most perfomant way to get random records from ActiveRecord. In fact, it's the only way to get random records from ActiveRecord. For now, it supports only PostgreSQL.

What about performance??

The perfomance screenshot

Installation

Install the gem and add it to the application's Gemfile by executing:

bundle add random-rails
Enter fullscreen mode Exit fullscreen mode

If bundler is not being used to manage dependencies, install the gem by executing:

gem install random-rails
Enter fullscreen mode Exit fullscreen mode

Usage

Just call random on your ActiveRecord model and enjoy:

User.random
# => [#<User id: 1, name: "John", ...>]
Enter fullscreen mode Exit fullscreen mode

You can also pass precision to a random method:

User.random(0.1)
# => [#<User id: 1, name: "Nikolas", ...>]
Enter fullscreen mode Exit fullscreen mode

Combine with other ActiveRecord methods? No problem:

User.where(age: 18..30).random(0.1).limit(10)
# => [#<User id: 1, name: "Nikolas", ...>, #<User id: 2, name: "John", ...>,
โ€ฆ
Enter fullscreen mode Exit fullscreen mode

Top comments (0)