PhoenixKitCatalogue.Catalogue.Counts (PhoenixKitCatalogue v0.18.0)

Copy Markdown View Source

Catalogue-level item and category counts. Includes both per-uuid helpers and single-query batch versions to avoid N+1 lookups when rendering catalogue lists with associated item / category counts.

Public surface is re-exported from PhoenixKitCatalogue.Catalogue.

Summary

Functions

Counts active items in a category subtree (the category itself and every V103 descendant). Used by the admin "delete category" modal to decide whether to ask the operator what should happen to the items.

Batch "has attached documents" counts for list rows: given resources (items / catalogues / row maps) whose data["files_folder_uuid"] points at their attachment folder, returns %{resource_uuid => count} of the NON-image, live files in that folder — the same set the product card's Files section lists (ProductCard.resolve_files/1: home folder, not trashed, not system-managed, not an image — photos are already conveyed by the featured thumb, so the paperclip means documents).

Counts non-deleted categories for a catalogue.

Returns a map of catalogue_uuid => non_deleted_category_count, in a single query. Useful for displaying category counts alongside a catalogue list (e.g. in the import wizard's catalogue picker) without N+1 lookups.

Counts deleted categories for a catalogue.

Total count of deleted entities (items + categories) for a catalogue.

Counts deleted items in a catalogue, including items without a category.

Counts non-deleted items in a catalogue, including items without a category.

Returns a map of %{catalogue_uuid => non_deleted_item_count} for all catalogues.

Functions

active_item_count_in_subtree(category_uuid)

@spec active_item_count_in_subtree(Ecto.UUID.t()) :: non_neg_integer()

Counts active items in a category subtree (the category itself and every V103 descendant). Used by the admin "delete category" modal to decide whether to ask the operator what should happen to the items.

attached_file_counts(resources)

@spec attached_file_counts([map()]) :: %{optional(String.t()) => non_neg_integer()}

Batch "has attached documents" counts for list rows: given resources (items / catalogues / row maps) whose data["files_folder_uuid"] points at their attachment folder, returns %{resource_uuid => count} of the NON-image, live files in that folder — the same set the product card's Files section lists (ProductCard.resolve_files/1: home folder, not trashed, not system-managed, not an image — photos are already conveyed by the featured thumb, so the paperclip means documents).

One grouped query for the whole page; resources without a folder simply don't appear in the map. Rescued to %{} — a Storage hiccup must not take down a list render.

category_count_for_catalogue(catalogue_uuid)

@spec category_count_for_catalogue(Ecto.UUID.t()) :: non_neg_integer()

Counts non-deleted categories for a catalogue.

category_counts_by_catalogue()

@spec category_counts_by_catalogue() :: %{
  required(Ecto.UUID.t()) => non_neg_integer()
}

Returns a map of catalogue_uuid => non_deleted_category_count, in a single query. Useful for displaying category counts alongside a catalogue list (e.g. in the import wizard's catalogue picker) without N+1 lookups.

deleted_category_count_for_catalogue(catalogue_uuid)

@spec deleted_category_count_for_catalogue(Ecto.UUID.t()) :: non_neg_integer()

Counts deleted categories for a catalogue.

deleted_count_for_catalogue(catalogue_uuid)

@spec deleted_count_for_catalogue(Ecto.UUID.t()) :: non_neg_integer()

Total count of deleted entities (items + categories) for a catalogue.

Used to determine whether to show the "Deleted" tab.

deleted_item_count_for_catalogue(catalogue_uuid)

@spec deleted_item_count_for_catalogue(Ecto.UUID.t()) :: non_neg_integer()

Counts deleted items in a catalogue, including items without a category.

item_count_for_catalogue(catalogue_uuid)

@spec item_count_for_catalogue(Ecto.UUID.t()) :: non_neg_integer()

Counts non-deleted items in a catalogue, including items without a category.

item_counts_by_catalogue()

@spec item_counts_by_catalogue() :: %{required(Ecto.UUID.t()) => non_neg_integer()}

Returns a map of %{catalogue_uuid => non_deleted_item_count} for all catalogues.

Single-query batch version of item_count_for_catalogue/1 — avoids N+1 when displaying item counts alongside a catalogue list. Includes items both in categories and directly attached to a catalogue (uncategorized).