Meteor-Community-Packages / Meteor-Community-Packages/denormalize

Selectors for parent collection cache

Open
#16 1 comment 3 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
20
Forks
15
PR merge metrics
No merged PRs in 30d

Description

It would be an interesting addition to be able to provide a selector for the parent collection. For example:

```js
// Only add a chairCount on furniture of type "table"
Furniture.cacheCount({
collection: Furniture,
referenceField: 'furnitureLink',
cacheField: 'chairCount',
parentSelector: { type: 'table' },
selector: { type: 'chair' },
})

// Only add a legCount on furniture of type "chair"
Furniture.cacheCount({
collection: Legs,
referenceField: 'furnitureLink',
cacheField: 'legCount',
parentSelector: { type: 'chair' },
})
```

This allows "polymorphic" collections to have different caches depending on their category, type, etc.

It is mostly done for keeping things clean, but one could also imagine using different cache configurations with the same name:

Here's a sarcastic example 🤣:
```js
Users.cacheCount({
collection: Users,
referenceField: 'friendIds',
cacheField: 'americanFriends',
parentSelector: { citizenShip: 'american' },
selector: { citizenShip: 'american' },
})

Users.cacheCount({
collection: Users,
referenceField: 'friendIds',
cacheField: 'americanFriends',
parentSelector: { citizenShip: 'european' },
selector: { citizenShip: { $in: ['north-american', 'south-american', 'american'] } },
})
```

You would be responsible for maintaining non-overlapping parent selectors of course, otherwise it will not work.

Contributor guide

Open the contributing guide

Research direction

No file or test is named in the issue. Start by tracing the existing Furniture.cacheCount API and its handling of selector and parent relationships; review how current cache configurations are represented, then define completion as supporting non-overlapping parentSelector configurations alongside the shown selector behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.