Refactor trending petitions query
Refactor trending petitions query

Use Arel over SQL strings and remove unnecessary `last_signed_at` condition.

The `last_signed_at` condition was added as a hint to the planner to restrict
the number of petition ids when scanning the signatures table but it actually
makes the query significantly slower at times by causing a nested loop scan.
The condition on `validated_at` restricts the number of signatures anyway so
we can safely remove it and see a 100x performance boost on the home page
when refreshing the cached trending petitions fragment.

Also add `created_at` to the ORDER BY clause so that on the small chance that
two petitions are trending at the same rate the sort order is consistent.

alphagov/e-petitions,unboxed/e-petitions,unboxed/e-petitions,unboxed/e-petitions,alphagov/e-petitions,alphagov/e-petitions,unboxed/e-petitions,alphagov/e-petitions