Skip to content

Commit

Permalink
Fix element queries ignoring disabled elements
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Aug 14, 2023
1 parent 47cb6d5 commit 95289cb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release Notes for Blitz

## 4.5.2 - 2023-08-14

### Fixed

- Fixed a bug in which tracked element queries were ignoring disabled elements when determining which cached pages to refresh ([#527](https://github.com/putyourlightson/craft-blitz/issues/527)).

## 4.5.1 - 2023-08-09

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "putyourlightson/craft-blitz",
"description": "Intelligent static page caching for creating lightning-fast sites.",
"version": "4.5.1",
"version": "4.5.2",
"type": "craft-plugin",
"homepage": "https://putyourlightson.com/plugins/blitz",
"license": "proprietary",
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/RefreshCacheHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ public static function getElementQueryCacheIds(ElementQueryRecord $elementQueryR
/** @var ElementQuery $elementQuery */
$elementQuery = $elementType::find();

// Get elements with all statuses
// https://github.com/putyourlightson/craft-blitz/issues/527
$elementQuery->status(null);

$params = Json::decodeIfJson($elementQueryRecord->params);

// If json decode failed
Expand Down
1 change: 1 addition & 0 deletions tests/TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ This document outlines the test specification for the Blitz plugin.
- Element query type records are returned when an entry is changed by custom fields used in the query.
- Element query type records are not returned when an entry is changed by custom fields not used in the query.
- Element query type records are returned when an entry is changed with the date updated used in the query.
- Element query cache IDs returned when a disabled entry is changed.

### [Site Uri](pest/Feature/SiteUriTest.php)

Expand Down
11 changes: 11 additions & 0 deletions tests/pest/Feature/RefreshCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@
->toHaveCount(0);
});

test('Element query cache IDs are returned when a disabled entry is changed', function() {
$entry = createEntry(enabled: false);
Blitz::$plugin->generateCache->addElementQuery(Entry::find());
Blitz::$plugin->generateCache->save(createOutput(), createSiteUri());
$refreshData = RefreshDataModel::createFromElement($entry);
$elementQueryRecord = ElementQueryRecord::find()->orderBy('id DESC')->one();

expect(RefreshCacheHelper::getElementQueryCacheIds($elementQueryRecord, $refreshData))
->toHaveCount(1);
});

test('Element query type records are returned when an entry is changed', function() {
$entry = createEntry();
Blitz::$plugin->generateCache->addElementQuery(Entry::find());
Expand Down

0 comments on commit 95289cb

Please sign in to comment.