Media path `{n}` token queries the posts collection and matches the wrong field

Open
#1,027 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript, node.js
Domain
api, backend

Research direction

Read endpoint-media/lib/utils.js:39, index.js:36, and media-type-count.js:19,34 to trace the collection and field used for media counts. Start by adding a regression case in test/unit/media-type-count.js with a media-type property and a media document; also check the promise handling and self-exclusion behavior described in the issue. Done means the count returns the expected result for media without matching unrelated posts, with tests covering both reported faults.

Written by the indexing model from the issue text.

Description

endpoint-media/lib/utils.js:39 passes collections.get("posts") to mediaTypeCount.get(),
though index.js:36 registers media. And media-type-count.js:19 reads
properties["media-type"] while line 34 matches properties.post-type, which media
documents don't have.

Measured with one photo in media and the properties getMediaProperties() produces: 0 via
both collections
, expected 1 — the two faults are independent, so neither fix works alone.
It isn't always 0, though: where a post-type shares the uploaded media-type's name the
count is that post count (18 photo posts, on my site). A plausible wrong number rather than
an obvious zero.

Two smaller things in the same file: line 9's !postsCollection.count() is an unawaited
promise, always truthy — what you removed from the posts copy in a3544343 — and there's no
uid/url self-exclusion (cf. 2634ac0b, #746).

test/unit/media-type-count.js doesn't catch any of it: it passes no media-type, so the
$match is null and matches the fixture's missing field. It stays green after fixing the
field name too.

No design question here — I can PR this whenever you want it.

Dominant language
JavaScript
Stars
392
Forks
39
Avg merge
22h 29m
Merged PRs (30d)
25

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from getindiekit/indiekit

All issues in getindiekit/indiekit

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.