Skip to content

Commit

Permalink
Sort envs returned by REST API by current build's scheduled_on time
Browse files Browse the repository at this point in the history
  • Loading branch information
peytondmurray committed Oct 3, 2024
1 parent d39e5b4 commit 0442238
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,10 @@ async def api_list_environments(
Returns
-------
Dict
Paginated JSON response containing the requested environments
Paginated JSON response containing the requested environments. Results are sorted by each
envrionment's build's scheduled_on time to ensure all results are returned when iterating
over pages in systems where the number of environments is changing while results are being
requested; see https://github.com/conda-incubator/conda-store/issues/859 for context
"""
with conda_store.get_db() as db:
if jwt:
Expand Down Expand Up @@ -712,10 +714,10 @@ async def api_list_environments(
schema.Environment,
exclude={"current_build"},
allowed_sort_bys={
"namespace": orm.Namespace.name,
"name": orm.Environment.name,
"scheduled_on": orm.Environment.current_build.scheduled_on,
},
default_sort_by=["namespace", "name"],
default_sort_by=["scheduled_on"],
default_order="asc",
)


Expand Down
9 changes: 5 additions & 4 deletions conda-store-server/conda_store_server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,11 @@ def list_environments(
Query
Sqlalchemy query containing the requested environments
"""
query = db.query(orm.Environment).join(orm.Environment.namespace)
query = (
db.query(orm.Environment)
.join(orm.Environment.namespace)
.join(orm.Environment.current_build)
)

if namespace:
query = query.filter(orm.Namespace.name == namespace)
Expand All @@ -343,9 +347,6 @@ def list_environments(
if not show_soft_deleted:
query = query.filter(orm.Environment.deleted_on == null())

if status or artifact or packages:
query = query.join(orm.Environment.current_build)

if status:
query = query.filter(orm.Build.status == status)

Expand Down

0 comments on commit 0442238

Please sign in to comment.