Change single query into 3 for 10-100x speed boost
Change single query into 3 for 10-100x speed boost

The single query to look up Links based on edition_id seemed to have
quite a nasty performance hit.

Based on 500 records:

```
 (397.5ms)  SELECT editions.id, "links"."link_type", "links"."target_content_id"
 FROM "links" INNER JOIN "link_sets" ON "link_sets"."id" = "links"."link_set_id"
 INNER JOIN documents ON documents.content_id = link_sets.content_id
 INNER JOIN editions ON editions.document_id = documents.id
 WHERE "editions"."id" IN (840183, 849586, 876569...)
 ORDER BY editions.id, "links"."link_type" ASC, "links"."position" ASC
```

Whereas with 3 queries we'd get the data in approx 9ms:

```
   (3.3ms)  SELECT "editions"."id", "content_id"
   FROM "editions"
   INNER JOIN "documents" ON "documents"."id" = "editions"."document_id"
   WHERE "editions"."id" IN (3171473, 3171474, 3171475...)
   (3.0ms)  SELECT "link_sets"."content_id", "link_sets"."id"
   FROM "link_sets"
   WHERE "link_sets"."content_id" IN ('5fbc6b2c-caa0-4946-a1cd-b206f381d819', '65b4e85b-51f0-449d-8d3a-e49f9f8ac99d', '71810925-a609-4015-becb-d661a7f64af3'...)
   (3.0ms)  SELECT "links"."link_set_id", "links"."link_type", "links"."target_content_id"
   FROM "links"
   WHERE "links"."link_set_id" IN (413458, 413832, 413922...)
   ORDER BY "links"."link_set_id" ASC, "links"."link_type" ASC, "links"."position" ASC
```

And overall method difference:

```
[15] pry(main)> puts Benchmark.measure { q.send(:old_query_link_set_links) }
0.008000   0.000000   0.008000 (  0.421056)
```

vs:

```
[14] pry(main)> puts Benchmark.measure { q.send(:query_link_set_links) }
0.016000   0.004000   0.020000 (  0.034990)
```

alphagov/publishing-api,alphagov/publishing-api