queryguard/laravel 问题修复 & 功能扩展

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

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

queryguard/laravel

Composer 安装命令:

composer require queryguard/laravel

包简介

Production query health for Laravel — continuous SQL monitoring, deploy regression tracking, AI-powered fix recipes.

README 文档

README

Production query health monitoring for Laravel. Catch slow queries, N+1 bugs, and missing indexes — with AI-powered fix suggestions and ready-to-run migrations.

Features

  • Slow Query Detection — track queries exceeding your threshold (default 500ms)
  • N+1 Detection — spot repeated query patterns within a single request
  • Missing Index Detection — identify unindexed columns in slow queries
  • AI-Powered Analysis — diagnosis and migration code via Claude or OpenAI (optional, BYO key)
  • Zero Production Overhead — configurable sampling, ignore lists, buffered processing
  • Privacy First — only normalized SQL templates leave your server, never values

Installation

composer require queryguard/laravel
php artisan migrate

Publish config (optional):

php artisan vendor:publish --provider="QueryGuard\QueryGuardServiceProvider" --tag="config"

Configuration

// config/queryguard.php
return [
    'enabled'               => env('QUERYGUARD_ENABLED', true),
    'sample_rate'           => env('QUERYGUARD_SAMPLE_RATE', 1.0),
    'slow_threshold_ms'     => 500,
    'n_plus_one_threshold'  => 10,
    'ignore' => [
        'tables' => ['telescope_*', 'pulse_*', 'jobs', 'sessions', 'cache'],
        'paths'  => ['horizon*', 'telescope*'],
    ],
    'storage' => [
        'retention_days' => 14,
    ],
    'explain' => [
        'enabled'        => true,
        'on_demand_only' => true,
    ],
    'ai' => [
        'provider' => env('QUERYGUARD_AI', null),  // 'anthropic' | 'openai' | null
        'api_key'  => env('QUERYGUARD_AI_KEY'),
        'model'    => env('QUERYGUARD_AI_MODEL', 'claude-sonnet-4-6'),
    ],
];

Usage

Report all issues

php artisan queryguard:report
php artisan queryguard:report --type=slow
php artisan queryguard:report --type=n_plus_one
php artisan queryguard:report --type=missing_index

AI analysis of a specific query

php artisan queryguard:analyze ab12cd34ef56

Requires QUERYGUARD_AI_KEY in .env. Returns diagnosis, root cause, suggested migration and Eloquent pattern.

Generate and apply a fix

php artisan queryguard:fix ab12cd34ef56

Generates a migration file. You review and run it yourself — QueryGuard never auto-applies migrations.

Signal a deploy (Cloud, Phase 3)

php artisan queryguard:deploy --sha=abc123 --branch=main

How It Works

Fingerprinting

Every SQL query is normalized into a template — all literals replaced with ?, IN lists collapsed:

Raw:      SELECT * FROM orders WHERE user_id = 42 AND status IN (1, 2, 3)
Template: SELECT * FROM orders WHERE user_id = ? AND status IN (?)
Hash:     ab12cd34ef56...

Identical templates across requests share one fingerprint, enabling accurate aggregation and N+1 detection.

Privacy guarantee

The Fingerprinter strips all literals before any data is persisted or transmitted. A CI test asserts this invariant — it fails if any raw number or string value leaks into a template.

Detectors

Detector Trigger
SlowQueryDetector max_ms >= slow_threshold_ms
NPlusOneDetector same fingerprint repeats >= n_plus_one_threshold times per request
MissingIndexDetector slow query WHERE/JOIN columns not covered by any index

Requirements

  • PHP 8.2+
  • Laravel 10, 11, or 12
  • MySQL 5.7+ or PostgreSQL 12+ or SQLite (testing)

Testing

composer test

Roadmap

  • v0.1 — Slow / N+1 / missing index detection, AI fix suggestions, migration generator
  • v0.2 — Cloud transport (batched metrics ingestion)
  • Cloud — Deploy-linked regression detection, Filament dashboard, Stripe billing

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固