|
17 | 17 | import packaging_legacy.version
|
18 | 18 |
|
19 | 19 | from pyramid_jinja2 import IJinja2Environment
|
| 20 | +from sqlalchemy import String, cast, func, select |
20 | 21 | from sqlalchemy.orm import joinedload
|
21 | 22 |
|
22 | 23 | from warehouse.packaging.interfaces import ISimpleStorage
|
|
26 | 27 |
|
27 | 28 |
|
28 | 29 | def _simple_index(request, serial):
|
29 |
| - # Fetch the name and normalized name for all of our projects |
30 |
| - projects = ( |
31 |
| - request.db.query(Project.name, Project.normalized_name, Project.last_serial) |
32 |
| - # Exclude projects that are in the `quarantine-enter` lifecycle status. |
33 |
| - # Use `is_distinct_from` method here to ensure that we select `NULL` records, |
34 |
| - # which would otherwise be excluded by the `==` operator. |
35 |
| - .filter( |
36 |
| - Project.lifecycle_status.is_distinct_from(LifecycleStatus.QuarantineEnter) |
| 30 | + # Fetch the name and last serial name for all of our projects |
| 31 | + query = select( |
| 32 | + func.array( |
| 33 | + select( |
| 34 | + func.json_build_object( |
| 35 | + cast("name", String), |
| 36 | + Project.name, |
| 37 | + cast("_last-serial", String), |
| 38 | + Project.last_serial, |
| 39 | + ) |
| 40 | + ) |
| 41 | + # Exclude projects that are in the `quarantine-enter` lifecycle status. |
| 42 | + # Use `is_distinct_from` method here to ensure that we select `NULL` |
| 43 | + # records, which would otherwise be excluded by the `==` operator. |
| 44 | + .filter( |
| 45 | + Project.lifecycle_status.is_distinct_from( |
| 46 | + LifecycleStatus.QuarantineEnter |
| 47 | + ) |
| 48 | + ).order_by(Project.normalized_name) |
37 | 49 | )
|
38 |
| - .order_by(Project.normalized_name) |
39 |
| - .all() |
40 | 50 | )
|
| 51 | + projects = request.db.execute(query).scalar() or [] |
41 | 52 |
|
42 | 53 | return {
|
43 | 54 | "meta": {"api-version": API_VERSION, "_last-serial": serial},
|
44 |
| - "projects": [{"name": p.name, "_last-serial": p.last_serial} for p in projects], |
| 55 | + "projects": projects, |
45 | 56 | }
|
46 | 57 |
|
47 | 58 |
|
|
0 commit comments