diff --git a/conda-store-server/conda_store_server/_internal/server/views/api.py b/conda-store-server/conda_store_server/_internal/server/views/api.py index 496e46f6..31522de5 100644 --- a/conda-store-server/conda_store_server/_internal/server/views/api.py +++ b/conda-store-server/conda_store_server/_internal/server/views/api.py @@ -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: @@ -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", ) diff --git a/conda-store-server/conda_store_server/api.py b/conda-store-server/conda_store_server/api.py index 7b937046..0b582c5d 100644 --- a/conda-store-server/conda_store_server/api.py +++ b/conda-store-server/conda_store_server/api.py @@ -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) @@ -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)