PhoenixKitCatalogue.Catalogue.Counts (PhoenixKitCatalogue v0.1.17)

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.

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.

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).