Skip to content


Subversion checkout URL

You can clone with
Download ZIP
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


"extended_ancestry" gem
Author and Copyright 2011: Luca Belmondo,
MIT License

This gem should e considered alpha stage, just a proof of concept to verify 7
a couple of ideas about the implementation of ancestry pattern.

It is heavily inspired to the excellent "ancestry" gem, by Stefan Kroes

--- Limitations ---

- some functionalities have not been implemented yet
- it needs some refinements
- it supports only Ruby 1.9 and Rails 3
- some tests need to be implemented to verify some specific scenarios

--- Rationale ---

Verify if it is possible to speed up rearrangement operations on relatively large trees.

Changing the parent of a node, should always cause the same number of queries, regardless
of the number of descendants.

To do that, a temporary standardized table is used. The computed values are put
this table, and its content is then used to make a cross update with the target table.

The implementation includes Sqlite, but only to be able to use the gem in development,
because Sqlite does not support true cross update statements, as far as I know.

Tests run on PostgreSQL by default, to run them on the other databases:

TEST_DATABASE=mysql rake
TEST_DATABASE=sqlite rake

See the spec_helper.rb to set up the databases.

To run the benchmarks and compare them to the ancestry gem:

ruby -I lib -I spec spec/benchmarks.rb

The benchmark measures the time required by the gems to change 20 times parent_id to a node with about 3,000 descendants.

A typical result on PostgreSQL is the following:

                          user    system      total         real
extended_ancestry     9.470000  0.050000   9.520000 ( 15.676685)
ancestry            107.490000  4.260000 111.750000 (141.237660)

Something went wrong with that request. Please try again.