Shopify/liquid — pull request #145 by boourns (2012-10-01 20:12:17+00:00)
Title: if the following tag is ['first','last' or 'size] defer to_liquid

@ssoroka @Soleone Please Review /cc @hornairs

Currently, if a liquid user executes `collection.products.first`, `products` will be converted to_liquid before the `.first` is applied.

If the drop provides an ActiveRelation object to the liquid engine, calling `.to_liquid` on the ActiveRelation will load all the objects, and then throw out all but the first.

If we defer calling .to_liquid until after we've applied `.first` then ActiveRecord will do the right thing and only load the single product.

This fix is a first-principals approach to solving the problem: if the following tag is in `['first', 'last', 'size']` and we've got an object that responds to the tag, send it before rendering to_liquid.

I feel like there's potential for a bigger refactor here, to recursively apply the following tags and only render .to_liquid when necessary.