Skip to content

Commit

Permalink
simple list: offload dictionary build to postgres (#17724)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewdurbin authored Mar 6, 2025
1 parent ef9978c commit 1d2b24f
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions warehouse/packaging/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import packaging_legacy.version

from pyramid_jinja2 import IJinja2Environment
from sqlalchemy import String, cast, func, select
from sqlalchemy.orm import joinedload

from warehouse.packaging.interfaces import ISimpleStorage
Expand All @@ -26,22 +27,32 @@


def _simple_index(request, serial):
# Fetch the name and normalized name for all of our projects
projects = (
request.db.query(Project.name, Project.normalized_name, Project.last_serial)
# Exclude projects that are in the `quarantine-enter` lifecycle status.
# Use `is_distinct_from` method here to ensure that we select `NULL` records,
# which would otherwise be excluded by the `==` operator.
.filter(
Project.lifecycle_status.is_distinct_from(LifecycleStatus.QuarantineEnter)
# Fetch the name and last serial name for all of our projects
query = select(
func.array(
select(
func.json_build_object(
cast("name", String),
Project.name,
cast("_last-serial", String),
Project.last_serial,
)
)
# Exclude projects that are in the `quarantine-enter` lifecycle status.
# Use `is_distinct_from` method here to ensure that we select `NULL`
# records, which would otherwise be excluded by the `==` operator.
.filter(
Project.lifecycle_status.is_distinct_from(
LifecycleStatus.QuarantineEnter
)
).order_by(Project.normalized_name)
)
.order_by(Project.normalized_name)
.all()
)
projects = request.db.execute(query).scalar() or []

return {
"meta": {"api-version": API_VERSION, "_last-serial": serial},
"projects": [{"name": p.name, "_last-serial": p.last_serial} for p in projects],
"projects": projects,
}


Expand Down

0 comments on commit 1d2b24f

Please sign in to comment.