{"repo":"the-rubies-way/random-rails","free":true,"listed":false,"github":"https://github.com/the-rubies-way/random-rails","clone":"git clone https://github.com/the-rubies-way/random-rails.git","description":"The most performed gem to get random record you ever seen! Available for Ruby on Rails with PostgreSQL right now!","language":"Ruby","stars":30,"topics":["activerecord","performance","postgresql","random","ruby","ruby-on-rails","sql","rails-perfomance"],"license":"MIT","category":"databases-storage","readme_excerpt":"RandomRails 🚀 The most performant way to get random records from ActiveRecord. Supports PostgreSQL , MySQL , and SQLite with intelligent strategy selection to replace slow ORDER BY RANDOM() queries. Why RandomRails? Traditional ORDER BY RANDOM() queries become extremely slow on large tables because they require sorting the entire dataset. RandomRails solves this by using: - TABLESAMPLE BERNOULLI for PostgreSQL (ultra-fast on large tables) - Efficient offset-based sampling for all databases - Intelligent strategy selection based on table size and database type - Configurable sampling methods for different use cases Performance Comparison Real-world benchmark results comparing RandomRails with traditional methods (10 iterations each): Sample Size ORDER BY RANDOM() User.random() User.sample() Performance Gain --------------- --------------------- ----------------- ----------------- ----------------------- 1,000 users 3.8359s 0.2157s 347.1409s 17.79x faster 10,000 users 6.1273s 2.7313s 369.7583s 2.24x faster 100,000 users 31.578s 3.6968s 369.4334s 8.54x faster 1,000,000 users 171.497s 5.3441s 373.6102s 32.09x faster Key Takeaways: - RandomRails consistently outperforms ORDER BY RANDOM() by 2-32x - Performance advantage increases dramatically with table size - Traditional User.sample() method performs poorly at scale Installation Add to your Gemfile: Or install directly: Examples Basic Usage Get a single random record: Get multiple random records: Chain with other ActiveRecord me","default_branch":null,"files":null,"tree":[],"storefront":"/r/the-rubies-way","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/the-rubies-way/random-rails/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}