b2pweb/bdf-prime-analyzer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

b2pweb/bdf-prime-analyzer

Composer 安装命令:

composer require b2pweb/bdf-prime-analyzer

包简介

Analyze queries generated by Prime ORM and dump unsafe or not optimized queries

README 文档

README

build codecov Packagist Version Total Downloads Type Coverage

Analyse executed queries during runtime to report suspicious queries or optimisations tips.

Usage

Install using composer

composer require --dev b2p/bdf-prime-analyzer

Register on unit test case

    public static function createApplication()
    {
        $app = require __DIR__ . '/../../app/application.php';
        // ...
        $app->register(new \Bdf\Prime\Analyzer\PrimeAnalyzerServiceProvider([
            'ignoredPath' => [dirname(__DIR__)],
            'dumpFormats' => [
                new \Bdf\Prime\Analyzer\Testing\DumpFormat\HtmlDumpFormat(__DIR__.'/prime-report.html'),
                new \Bdf\Prime\Analyzer\Testing\DumpFormat\ConsoleDumpFormat(),
            ],
            'ignoredAnalysis' => [],
        ]));
        
        // ...

        return $app;
    }

To ignore analysis on a single query, simple add the @prime-analyzer-ignore [analisys] tag on the execute line.

$credentials = $device->relation('credentials')->first(); // @prime-analyzer-ignore optimisation sort

You can also ignore analysis globally on the entity, using the docblock of the Mapper class. Unlike the query inline ignore, parameters can be set to ignore only the listed attributes.

/**
 * Mapper for TourOperation
 *
 * @prime-analyzer-ignore sort position
 * @prime-analyzer-ignore not_declared my_raw_attribute
 * @prime-analyzer-ignore index
 */
class TourOperationMapper extends Mapper
{
    // ...
}

Options

Available options to set on the service provider registration :

  • ignoredPath : List of path to ignore on the query analysis. For example the tests directory.
  • ignoredAnalysis : List of analysis to ignore. See AnalysisTypes. AnalysisTypes::optimisations() can be used to only report dangerous queries.
  • dumpFormats : List of DumpFormatInterface instances.
    • ConsoleDumpFormat : for dump in console after the end of tests
    • HtmlDumpFormat : for dump into an HTML file
  • register : Set false to disable reporting

Analysis

  • like : Analyse the LIKE filters, and dump values without wildcard _ or %.
  • index : Dump queries without any indexes. Queries with at least one relation or join are ignored.
  • not_declared : Dump use of undeclared attributes (i.e. attributes not in mapper).
  • sort : Dump queries with an ORDER clause on non-indexed attribute. You may ignore those reports if the returned set is small.
  • or : Dump queries with an OR clause not nested into parenthesis.
  • optimisation : Dump queries which can be optimised using KeyValueQuery or findById. See limitations for more information.
  • relation_distant_key : Dump queries using the distant key of a relation instead of the local key. This cause a useless join. Do not handle "through" relations.
  • write : Dump invalid update or insert queries. Analyse undeclared attributes and values types.
  • n+1 : Dump N+1 or loop queries. To raise an N+1, the queries must be at least called twice with the same stacktrace. Ignore only if the loop is desired (like walker).

Limitations

  • Do not handle raw expressions or join.
  • optimisation may generate report on relation query, which cannot be fixed, and should be ignored.
  • n+1 may report a false positive in case of load() two relations on same entity (ex: $orderCustomer.load(['lading', 'delivery'])).
  • Always verify indexes. The index analysis do not replace an EXPLAIN.

统计信息

  • 总下载量: 4.7k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-05-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固