Skip to content

Re-think inversion of filters for multiple collections #10704

Description

@kirrg001

State

Ghost supports multiple collections. Each collection should own unique resources, because each resource should only have one url.

Problem

If you do not read our docs carefully, it can happen that multiple collections try to own the same resources.

Example:

collections:
  /first/:
    permalink: /first/{slug}/
    filter: tag:en

  /second/:
    permalink: /second/{slug}/

First collection will query the database and filter out posts which are tagged with "en".
Second collection will query the database without filter. Both will receive a post which is tagged with "en".

This will break pagination because we have to manually remove the "en" tagged posts from the output e.g. you fetch 10 posts on the first page, but we can only display 8 and the second page has another 10 posts. Pagination is broken.

To avoid this, we tell people to use inverse filters.

collections:
  /first/:
    permalink: /first/{slug}/
    filter: tag:en

  /second/:
    permalink: /second/{slug}/
    filter: tag:-en

Solution

Either we keep the restriction for using inverted filters or we have to find a way to mark which post belongs to which collection on the database layer and add a where clause when querying the database. This needs discussion.

A first good step to avoid that people are running into this could be to add a validation rule for the routes.yaml file (if you make use of multiple collections and one of the collections is using a filter, print a warning).

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects:routingrelated to the url service & dynamic routing featuresaffects:serverIssues relating to the server or core of Ghostlater[triage] Things we intend to work but are not immediate priorityneeds:info[triage] Blocked on missing information

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions