DEV Community

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

Posted on

1

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

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay