spree/spree — pull request #3186 by balexand (2013-06-11 19:14:44+00:00)
Title: add user_id index to spree_orders

If you update a cart (for example, change the quantity of a line item and click "update") while a user is logged in, the following query is executed:

```sql
SELECT "spree_orders".* FROM "spree_orders" WHERE "spree_orders"."user_id" = 2 AND "spree_orders"."completed_at" IS NULL ORDER BY created_at DESC LIMIT 1
```

This results in a table scan without the index that is created by this patch. Also, it's just good practice to index a foreign key that you know will be queried against.