Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selectors for parent collection cache #16

Open
Floriferous opened this issue May 6, 2019 · 1 comment
Open

Selectors for parent collection cache #16

Floriferous opened this issue May 6, 2019 · 1 comment

Comments

@Floriferous
Copy link
Contributor

Floriferous commented May 6, 2019

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

// 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 🤣:

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.

@Fen747
Copy link

Fen747 commented Sep 15, 2020

Just floating this up, as we face a situation that would benefits from this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants