Skip to content

Commit

Permalink
Add ability to ignore hints
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Oct 1, 2024
1 parent c6460c2 commit adc84af
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 5 deletions.
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

## 5.9.0 - Unreleased

### Added

- Added the ability to ignore hints in the Blitz Hints utility.

## 5.8.1 - 2024-10-01

### 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": "5.8.1",
"version": "5.9.0",
"type": "craft-plugin",
"homepage": "https://putyourlightson.com/plugins/blitz",
"license": "proprietary",
Expand Down
2 changes: 1 addition & 1 deletion src/Blitz.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static function config(): array
/**
* @inheritdoc
*/
public string $schemaVersion = '5.8.0';
public string $schemaVersion = '5.9.0';

/**
* @inheritdoc
Expand Down
13 changes: 13 additions & 0 deletions src/controllers/HintsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,17 @@ public function actionClear(): Response

return $this->redirectToPostedUrl();
}

/**
* Ignores a specific hint.
*/
public function actionIgnore(): Response
{
$this->requirePostRequest();

$id = Craft::$app->getRequest()->getRequiredBodyParam('id');
Blitz::$plugin->hints->ignore($id);

return $this->redirectToPostedUrl();
}
}
5 changes: 4 additions & 1 deletion src/helpers/HintsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class HintsHelper extends Component
*/
public static function getCount(): int
{
return HintRecord::find()->count();
return HintRecord::find()
->where(['ignored' => false])
->count();
}

/**
Expand All @@ -35,6 +37,7 @@ public static function getAll(): array

/** @var HintRecord[] $hintRecords */
$hintRecords = HintRecord::find()
->where(['ignored' => false])
->orderBy(['dateUpdated' => SORT_DESC])
->all();

Expand Down
1 change: 1 addition & 0 deletions src/migrations/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ protected function createTables(): bool
'template' => $this->string()->notNull(),
'line' => $this->integer(),
'stackTrace' => $this->text(),
'ignored' => $this->boolean(),
'dateCreated' => $this->dateTime()->notNull(),
'dateUpdated' => $this->dateTime()->notNull(),
'uid' => $this->uid(),
Expand Down
31 changes: 31 additions & 0 deletions src/migrations/m241001_120000_add_ignored_column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace putyourlightson\blitz\migrations;

use craft\db\Migration;
use putyourlightson\blitz\records\HintRecord;

class m241001_120000_add_ignored_column extends Migration
{
/**
* @inheritdoc
*/
public function safeUp(): bool
{
if (!$this->db->columnExists(HintRecord::tableName(), 'ignored')) {
$this->addColumn(HintRecord::tableName(), 'ignored', $this->boolean()->defaultValue(false)->after('stackTrace'));
}

return true;
}

/**
* @inheritdoc
*/
public function safeDown(): bool
{
echo self::class . " cannot be reverted.\n";

return true;
}
}
5 changes: 5 additions & 0 deletions src/models/HintModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class HintModel extends Model
*/
public array $stackTrace = [];

/**
* @var bool
*/
public bool $ignored = false;

/**
* @var DateTime|null
*/
Expand Down
1 change: 1 addition & 0 deletions src/records/HintRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @property string $template
* @property int $line
* @property array $stackTrace
* @property bool $ignored
* @property DateTime $lastUpdated
*/
class HintRecord extends ActiveRecord
Expand Down
13 changes: 13 additions & 0 deletions src/services/HintsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ public function clear(int $id): void
]);
}

/**
* Ignores a hint.
*
* @since 5.9.0
*/
public function ignore(int $id): void
{
HintRecord::updateAll(
['ignored' => true],
['id' => $id],
);
}

/**
* Checks for opportunities to eager-load elements.
*/
Expand Down
5 changes: 3 additions & 2 deletions src/templates/_utilities/hints/components/hints.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<th>Hint</th>
<th>Template</th>
<th class="nowrap">Last Occurrence</th>
<th style="width: 14px;"></th>
<th style="width: 62px;"></th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -65,7 +65,8 @@
{{ hint.dateUpdated|timestamp }}
</td>
<td>
<a sprig s-method="post" s-action="blitz/hints/clear" s-val:id="{{ hint.id }}" class="delete icon" title="{{ 'Delete'|t('app') }}" role="button"></a>
<button sprig s-method="post" s-action="blitz/hints/ignore" s-val:id="{{ hint.id }}" class="icon" data-icon="eye-slash" title="{{ 'Ignore'|t('blitz') }}" role="button"></button>
<button sprig s-method="post" s-action="blitz/hints/clear" s-val:id="{{ hint.id }}" class="delete icon" title="{{ 'Delete'|t('app') }}" role="button"></button>
</td>
</tr>
{% endfor %}
Expand Down

0 comments on commit adc84af

Please sign in to comment.