Skip to content

Commit

Permalink
2.0.0-beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Feb 14, 2024
1 parent 5531616 commit 5c39ff9
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 79 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/code-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Code Analysis

on:
pull_request: null
push:
branches:
- develop
- v2
workflow_dispatch:
permissions:
contents: read
jobs:
code_analysis:
strategy:
fail-fast: false
matrix:
actions:
- name: 'PHPStan'
run: composer phpstan
- name: 'Coding Standards'
run: composer fix-cs
name: ${{ matrix.actions.name }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Setup PHP
id: setup-php
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: 'ctype,curl,dom,iconv,imagick,intl,json,mbstring,openssl,pcre,pdo,reflection,spl,zip'
ini-values: post_max_size=256M, max_execution_time=180, memory_limit=512M
tools: composer:v2
- name: Install Composer dependencies
run: composer install --no-interaction --no-ansi --no-progress
- run: ${{ matrix.actions.run }}
28 changes: 3 additions & 25 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,7 @@
# Release Notes for Blitz Hints

## 1.1.1 - 2023-11-01
## 2.0.0-beta.1 - 2024-02-14

### Changed
### Added

- Changed the module and utility icon.

## 1.1.0 - 2023-10-31

### Changed

- Templates that exist in the vendor folder path are now ignored ([#574](https://github.com/putyourlightson/craft-blitz/issues/574)).

## 1.0.2 - 2023-03-03

### Changed

- Replaced `.collect()` with `.all()` in hint example.

## 1.0.1 - 2022-05-16

### Fixed

- Fixed incorrect behaviour in environments in which `devMode` was disabled.

## 1.0.0 - 2022-05-16

- Initial release.
- Added compatibility with Craft 5.0.0.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "putyourlightson/craft-blitz-hints",
"description": "Provides templating performance hints.",
"version": "1.1.1",
"version": "2.0.0-beta.1",
"type": "craft-module",
"license": "mit",
"require": {
"php": "^8.0.2",
"craftcms/cms": "^4.0.0"
"php": "^8.2",
"craftcms/cms": "^5.0.0-beta.1"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/BlitzHints.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function(RegisterTemplateRootsEvent $event) {
*/
private function _registerUtilities(): void
{
Event::on(Utilities::class, Utilities::EVENT_REGISTER_UTILITY_TYPES,
Event::on(Utilities::class, Utilities::EVENT_REGISTER_UTILITIES,
function(RegisterComponentTypesEvent $event) {
$event->types[] = HintsUtility::class;
}
Expand Down
67 changes: 18 additions & 49 deletions src/services/HintsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use craft\base\Component;
use craft\base\FieldInterface;
use craft\elements\db\ElementQuery;
use craft\elements\db\MatrixBlockQuery;
use craft\services\Deprecator;
use putyourlightson\blitzhints\models\HintModel;
use putyourlightson\blitzhints\records\HintRecord;
Expand Down Expand Up @@ -115,44 +114,6 @@ public function clear(int $id): void
* Checks for opportunities to eager-loading elements.
*/
public function checkElementQuery(ElementQuery $elementQuery): void
{
if ($elementQuery instanceof MatrixBlockQuery) {
$this->_checkMatrixRelations($elementQuery);
} else {
$this->_checkBaseRelations($elementQuery);
}
}

/**
* Saves any hints that have been prepared.
*/
public function save(): void
{
$db = Craft::$app->getDb();

foreach ($this->_hints as $hint) {
$db->createCommand()
->upsert(
HintRecord::tableName(),
[
'fieldId' => $hint->fieldId,
'template' => $hint->template,
'routeVariable' => $hint->routeVariable,
'line' => $hint->line,
],
[
'line' => $hint->line,
])
->execute();
}
}

/**
* Checks base relations.
*
* @see \craft\fields\BaseRelationField::normalizeValue
*/
private function _checkBaseRelations(ElementQuery $elementQuery): void
{
$join = $elementQuery->join[0] ?? null;

Expand All @@ -177,19 +138,27 @@ private function _checkBaseRelations(ElementQuery $elementQuery): void
}

/**
* Checks matrix relations.
*
* @see MatrixBlockQuery::beforePrepare
* Saves any hints that have been prepared.
*/
private function _checkMatrixRelations(MatrixBlockQuery $elementQuery): void
public function save(): void
{
if (empty($elementQuery->fieldId) || empty($elementQuery->ownerId)) {
return;
}

$fieldId = is_array($elementQuery->fieldId) ? $elementQuery->fieldId[0] : $elementQuery->fieldId;
$db = Craft::$app->getDb();

$this->_addFieldHint($fieldId);
foreach ($this->_hints as $hint) {
$db->createCommand()
->upsert(
HintRecord::tableName(),
[
'fieldId' => $hint->fieldId,
'template' => $hint->template,
'routeVariable' => $hint->routeVariable,
'line' => $hint->line,
],
[
'line' => $hint->line,
])
->execute();
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/HintsUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function id(): string
/**
* @inheritdoc
*/
public static function iconPath(): ?string
public static function icon(): ?string
{
$iconPath = Craft::getAlias('@putyourlightson/blitzhints/icon-mask.svg');

Expand Down

0 comments on commit 5c39ff9

Please sign in to comment.