github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

alvarobp / inverse_sortable

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 5
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Sets negative timestamps on Active Record models for efficiently sort in reverse order. — Read more

  cancel

http://github.com/alvarobp/inverse_sortable

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Added indexes and use of extension on benchmarks 
alvarobp (author)
Sun Jun 14 05:57:16 -0700 2009
commit  9ffeced256426f835bfac854b998a4b1ac5f3019
tree    9cdc689f9cdcefb5160a3077fd5f779af972652e
parent  cec6cc7eab17b6ecd3bd01f395c1f93c537f3a84
inverse_sortable /
name age
history
message
file Manifest Loading commit data...
file README.rdoc
file Rakefile
file TODO
directory benchmark/
file init.rb
file inverse_sortable.gemspec
directory lib/
directory test/
README.rdoc

inverse_sortable

Sets negative timestamps on Active Record models for efficiently sort in reverse order.

Install

  sudo gem install alvarobp-inverse_sortable --source http://gems.github.com

Add to environment.rb:

  config.gem "alvarobp-inverse_sortable", :lib => "inverse_sortable"

Usage

As a very simple plugin, using it is simple. Just add an integer attribute called "created_at_inverse" to your model. Afterwards you can make that model inverse sortable, for example:

  class Film < ActiveRecord::Base
    acts_as_inverse_sortable
  end

Therefore, you can get an inverse sorted array of Films with

  Film.find(:all, :order => 'created_at_inverse')

Test

Just do

  rake test

Benchmarks

I ran some benchmarks to see how efficient is this method. Well, most of the times benchmarks showed that this method is more efficient than "ORDER BY created_at DESC" as the table grows.

Just in case you want to run these benchmarks, you will need a mysql database (maybe other engines as well) and configure it at the top of benchmark/benchmark.rb file.

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server