Skip to content

Commit

Permalink
Don't include draft/revision blocks in Matrix queries by default
Browse files Browse the repository at this point in the history
Resolves #4790
  • Loading branch information
brandonkelly committed Aug 22, 2019
1 parent 6ceabc7 commit 4fc9108
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Improved the performance of element duplication on multi-site installs.
- Edit Entry pages now get updated preview target URLs after saving a draft, in case the URLs have changed.
- Improved the performance of `craft\web\View::renderString()` for templates that don’t contain any Twig code.
- Matrix block queries no longer include blocks owned by drafts or revisions by default. ([#4790](https://github.com/craftcms/cms/issues/4790))

### Removed
- Removed `craft\base\ElementInterface::getSource()`. ([#4754](https://github.com/craftcms/cms/issues/4754))
Expand Down
11 changes: 11 additions & 0 deletions src/elements/db/MatrixBlockQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,17 @@ protected function beforePrepare(): bool
$this->subQuery->andWhere(Db::parseParam('matrixblocks.typeId', $this->typeId));
}

// Ignore revision/draft blocks by default
if (!$this->id && !$this->ownerId) {
// todo: we will need to expand on this when Matrix blocks can be nested.
$this->subQuery
->innerJoin(Table::ELEMENTS . ' owners', '[[owners.id]] = [[matrixblocks.ownerId]]')
->andWhere([
'owners.draftId' => null,
'owners.revisionId' => null,
]);
}

return parent::beforePrepare();
}

Expand Down

0 comments on commit 4fc9108

Please sign in to comment.