Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort envs returned by REST API by current build's scheduled_on time #881

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading