Assets: always sort the generated online asset listing

The asset listing generator now sorts the assets, by file, then ID type,
then asset name. Sorting by file places related assets together, and
minimises the repeats of the same file across multiple listing pages.

The other sorting is just there to ensure stability of the generated
listing, so that diffs between generator runs are clean.

Pull Request: https://projects.blender.org/blender/blender/pulls/158637
This commit is contained in:
Sybren A. Stüvel 2026-05-15 14:00:39 +02:00
parent 5f2067df3e
commit b61c9f7fe9

View file

@ -90,6 +90,8 @@ def cli_main(arguments_raw: argparse.Namespace) -> None:
assets.extend(assets_in_file)
files.append(bfile_info)
_sort_assets(assets)
# Write the listing index and the pages:
asset_index_pages = pagination.paginate_asset_list(assets, files, arguments.page_size)
index_path = _write_json_files(arguments, asset_index_pages)
@ -114,6 +116,25 @@ def _toplevel_meta_read(meta_json_path: Path) -> api_models.AssetLibraryMeta:
return metadata
def _sort_assets(assets: list[api_models.AssetV1]) -> None:
"""Sorts the assets in-place.
Sorting helps to get the generated listing stable, so that a diff between
two runs of the generator is as clean as possible.
"""
# Sort assets by their primary filename first. This places related assets together, and minimizes the repeats of the
# same file across multiple listing pages.
def sort_key(asset: api_models.AssetV1) -> tuple[str, str, str]:
if asset.files:
first_file = asset.files[0].lower()
else:
first_file = ""
return (first_file, asset.id_type.lower(), asset.name.lower())
assets.sort(key=sort_key)
def _write_json_files(
arguments: CLIArguments,
asset_index_pages: list[api_models.AssetLibraryIndexPageV1],