Skip to content

fix(core): exclude unpublished entries from taxonomy term counts - #1839

Closed
ColoradoClimbr wants to merge 1 commit into
emdash-cms:mainfrom
Emdash-Bug-Testing:fix/581-taxonomy-counts-unpublished
Closed

ColoradoClimbr wants to merge 1 commit into
emdash-cms:mainfrom
Emdash-Bug-Testing:fix/581-taxonomy-counts-unpublished

Conversation

@ColoradoClimbr

Copy link
Copy Markdown
Contributor

What does this PR do?

getTaxonomyTermCounts() aggregated content_taxonomies with no status filter, so a draft post attached to a term inflated that term's count in widgets like the "Categories" sidebar even though the draft never renders publicly.

content_taxonomies has no FK to the per-collection ec_* tables that hold status, so the fix joins against each distinct collection present in the pivot and applies the same published-or-scheduled-and-due condition loader.ts already uses for content queries (buildStatusCondition, now exported for reuse here).

Closes #581

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (n/a — no new strings, count values only)
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion (n/a — bug fix)

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Sonnet 5

Screenshots / test output

packages/core/tests/unit/taxonomies/get-taxonomy-terms.test.ts — 3/3 pass; pnpm lint:quick clean; pnpm typecheck clean. (Full-suite run also shows 4 pre-existing failures in tests/unit/cli/bundle-utils.test.ts unrelated to this change — Windows/Git-Bash tar path mangling in the local dev environment, reproduces identically on main.)

Opened as draft: fork already has several open PRs against this repo (non-collaborator open-PR limit).

getTaxonomyTermCounts() aggregated content_taxonomies with no status
filter, so a draft post attached to a term inflated that term's count
in widgets like the "Categories" sidebar even though the draft never
renders publicly.

content_taxonomies has no FK to the per-collection ec_* tables that
hold status, so the fix joins against each distinct collection present
in the pivot and applies the same published-or-scheduled-and-due
condition loader.ts already uses for content queries (buildStatusCondition,
now exported for reuse here).

Fixes #581
@changeset-bot

changeset-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8c4c6a9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/do-demo-site Patch
@emdash-cms/do-solo-demo-site Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@1839

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@1839

@emdash-cms/auth-atproto

npm i https://pkg.pr.new/@emdash-cms/auth-atproto@1839

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@1839

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@1839

@emdash-cms/contentful-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/contentful-to-portable-text@1839

emdash

npm i https://pkg.pr.new/emdash@1839

create-emdash

npm i https://pkg.pr.new/create-emdash@1839

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@1839

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/@emdash-cms/plugin-cli@1839

@emdash-cms/plugin-types

npm i https://pkg.pr.new/@emdash-cms/plugin-types@1839

@emdash-cms/registry-client

npm i https://pkg.pr.new/@emdash-cms/registry-client@1839

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/@emdash-cms/registry-lexicons@1839

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/@emdash-cms/sandbox-workerd@1839

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@1839

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@1839

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@1839

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@1839

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@1839

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@1839

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/@emdash-cms/plugin-field-kit@1839

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@1839

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@1839

commit: 8c4c6a9

@ascorbic ascorbic added this to the 1.0 milestone Jul 8, 2026
@ascorbic

ascorbic commented Jul 9, 2026

Copy link
Copy Markdown
Member

Thanks for your work on this. There are currently several overlapping PRs that each manage part of this, but none of them manage the lot. I've found the simplest solution is to create a new PR inspired by all of them. For that reason I'm going to close this in favour of #1892

@ascorbic ascorbic closed this Jul 9, 2026
ascorbic added a commit that referenced this pull request Jul 9, 2026
…1892)

* fix(taxonomies): count only publicly visible entries in term counts (#581)

Term usage counts aggregated the content_taxonomies pivot directly, so
drafts, scheduled-future, and trashed entries inflated the counts shown
in the Categories/Tags widgets, on term pages, and in the admin term
list. All three paths now share a single UNION ALL count query that
joins the content tables, filters with buildStatusCondition (published
or scheduled-and-due) and deleted_at IS NULL, and scopes to the
taxonomy's declared collections.

Consolidates the fixes proposed in #1839, #822, and #593.

* ci: update query-count snapshots

* fix(taxonomies): include collection scope in term-count request-cache key

Per-locale rows of the same taxonomy def can drift in their declared
collections, and a future caller may pass a narrower scope; keying the
request cache by taxonomy name alone let the first scope poison the
entry for the rest of the request. Raised by review on #1892.

---------

Co-authored-by: emdashbot[bot] <emdashbot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unpublished Posts are included in Category counts

2 participants