{"id":13620153,"url":"https://github.com/halilcosdu/laravel-slower","last_synced_at":"2026-04-09T13:22:48.554Z","repository":{"id":237896995,"uuid":"795448263","full_name":"halilcosdu/laravel-slower","owner":"halilcosdu","description":"★ Laravel Slower: Optimize Your DB Queries with AI","archived":false,"fork":false,"pushed_at":"2025-03-03T13:25:31.000Z","size":72,"stargazers_count":351,"open_issues_count":0,"forks_count":19,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-02T09:48:54.865Z","etag":null,"topics":["laravel","log","optimization","php","query","slow","slowquery","slowquerylog"],"latest_commit_sha":null,"homepage":"https://laravel-slower.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/halilcosdu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"buy_me_a_coffee":"halilcosdu5"}},"created_at":"2024-05-03T09:56:32.000Z","updated_at":"2025-03-21T15:05:42.000Z","dependencies_parsed_at":"2024-06-10T14:58:32.525Z","dependency_job_id":"eb48a9af-0974-44da-aaa6-28ef733ee459","html_url":"https://github.com/halilcosdu/laravel-slower","commit_stats":null,"previous_names":["halilcosdu/laravel-slower"],"tags_count":14,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halilcosdu%2Flaravel-slower","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halilcosdu%2Flaravel-slower/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halilcosdu%2Flaravel-slower/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halilcosdu%2Flaravel-slower/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/halilcosdu","download_url":"https://codeload.github.com/halilcosdu/laravel-slower/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248945817,"owners_count":21187393,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","log","optimization","php","query","slow","slowquery","slowquerylog"],"created_at":"2024-08-01T21:00:52.868Z","updated_at":"2026-04-09T13:22:48.536Z","avatar_url":"https://github.com/halilcosdu.png","language":"PHP","funding_links":["https://buymeacoffee.com/halilcosdu5"],"categories":["PHP","SDKs \u0026 Libraries"],"sub_categories":["PHP \u0026 Laravel"],"readme":"# Laravel Slower: Optimize Your DB Queries with AI\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/halilcosdu/laravel-slower.svg?style=flat-square)](https://packagist.org/packages/halilcosdu/laravel-slower)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/halilcosdu/laravel-slower/run-tests.yml?branch=main\u0026label=tests\u0026style=flat-square)](https://github.com/halilcosdu/laravel-slower/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/halilcosdu/laravel-slower/fix-php-code-style-issues.yml?branch=main\u0026label=code%20style\u0026style=flat-square)](https://github.com/halilcosdu/laravel-slower/actions?query=workflow%3A\"Fix+PHP+code+style+issues\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/halilcosdu/laravel-slower.svg?style=flat-square)](https://packagist.org/packages/halilcosdu/laravel-slower)\n\n\n\u003ca href=\"https://trendshift.io/repositories/10023\" target=\"_blank\"\u003e\u003cimg src=\"https://trendshift.io/api/badge/repositories/10023\" alt=\"halilcosdu%2Flaravel-slower | Trendshift\" style=\"width: 250px; height: 55px;\" width=\"250\" height=\"55\"/\u003e\u003c/a\u003e\n\n\nLaravel Slower is a powerful package designed for Laravel developers who want to enhance the performance of their applications. It intelligently identifies slow database queries and leverages AI to suggest optimal indexing strategies and other performance improvements. Whether you're debugging or routinely monitoring your application, Laravel Slower provides actionable insights to streamline database interactions.\n\n## Requirements\n\n- PHP 8.2 or higher\n- Laravel 10.x, 11.x, 12.x, or 13.x\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require halilcosdu/laravel-slower\n```\n\nYou can publish the config file with:\n\n```bash\nphp artisan vendor:publish --tag=\"slower-config\"\n```\n\nThis is the contents of the published config file:\n\nYou can disable AI recommendations by setting the `ai_recommendation` key to `false` in the config file. If you disable AI recommendations, the package will not make any API requests to OpenAI.\n\n```php\n\u003c?php\n\n// config for HalilCosdu/Slower\n\nuse HalilCosdu\\Slower\\Models\\SlowLog;\n\nreturn [\n    'enabled' =\u003e env('SLOWER_ENABLED', true),\n    'threshold' =\u003e env('SLOWER_THRESHOLD', 10000),\n    'resources' =\u003e [\n        'table_name' =\u003e (new SlowLog)-\u003egetTable(),\n        'model' =\u003e SlowLog::class,\n    ],\n    'ai_recommendation' =\u003e env('SLOWER_AI_RECOMMENDATION', true),\n    'recommendation_model' =\u003e env('SLOWER_AI_RECOMMENDATION_MODEL', 'gpt-4'),\n    'recommendation_use_explain' =\u003e env('SLOWER_AI_RECOMMENDATION_USE_EXPLAIN', true),\n    'ignore_explain_queries' =\u003e env('SLOWER_IGNORE_EXPLAIN_QUERIES', true),\n    'ignore_insert_queries' =\u003e env('SLOWER_IGNORE_INSERT_QUERIES', true),\n    'open_ai' =\u003e [\n        'api_key' =\u003e env('OPENAI_API_KEY'),\n        'organization' =\u003e env('OPENAI_ORGANIZATION'),\n        'request_timeout' =\u003e env('OPENAI_TIMEOUT'),\n    ],\n    'prompt' =\u003e env('SLOWER_PROMPT', 'As a distinguished database optimization expert, your expertise is invaluable for refining SQL queries to achieve maximum efficiency. Schema json provide list of indexes and column definitions for each table in query. Also analyse the output of EXPLAIN ANALYSE and provide recommendations to optimize query. Please examine the SQL statement provided below including EXPLAIN ANALYSE query plan. Based on your analysis, could you recommend sophisticated indexing techniques or query modifications that could significantly improve performance and scalability?'),\n];\n\n```\n\nYou can publish and run the migrations with:\n\n```bash\nphp artisan vendor:publish --tag=\"slower-migrations\"\n```\n\n```bash\nphp artisan migrate\n```\n\n```php\npublic function up()\n{\n    Schema::create(config('slower.resources.table_name'), function (Blueprint $table) {\n        $table-\u003eid();\n        $table-\u003eboolean('is_analyzed')-\u003edefault(false)-\u003eindex();\n        $table-\u003elongtext('bindings');\n        $table-\u003elongtext('sql');\n        $table-\u003efloat('time')-\u003enullable()-\u003eindex();\n        $table-\u003estring('connection');\n        $table-\u003estring('connection_name')-\u003enullable();\n        $table-\u003elongtext('raw_sql');\n        $table-\u003elongtext('recommendation')-\u003enullable();\n\n        $table-\u003etimestamps();\n    });\n}\n\npublic function down(): void\n{\n    Schema::dropIfExists(config('slower.resources.table_name'));\n}\n```\n\n\n## Usage\nYou can register the commands with your scheduler.\n```php\nphp artisan slower:clean /*{days=15}  Delete records older than 15 days.*/\nphp artisan slower:analyze /*Analyze the records where is_analyzed=false*/\n```\n\n```php\n    use HalilCosdu\\Slower\\Commands\\AnalyzeQuery;\n    use HalilCosdu\\Slower\\Commands\\SlowLogCleaner;\n\n    protected $commands = [\n        AnalyzeQuery::class,\n        SlowLogCleaner::class,\n    ];\n\n    /**\n     * Define the application's command schedule.\n     */\n    protected function schedule(Schedule $schedule): void\n    {\n        $schedule-\u003ecommand(AnalyzeQuery::class)-\u003erunInBackground()-\u003edaily();\n        $schedule-\u003ecommand(SlowLogCleaner::class)-\u003erunInBackground()-\u003edaily();\n    }\n```\n```php\n$model = \\HalilCosdu\\Slower\\Models\\SlowLog::first();\n\n\\HalilCosdu\\Slower\\Facades\\Slower::analyze($model): Model;\n\ndd($model-\u003eraw_sql); /*select count(*) as aggregate from \"product_prices\" where \"product_id\" = '1' and \"price\" = '0' and \"discount_total\" \u003e '0'*/\n\ndd($model-\u003erecommendation);\n```\n### Example Screen\n\n\u003ca href=\"https://i.ibb.co/J2xvB1y/Screenshot-2024-05-11-at-00-24-52.png\"\u003e\n\u003cimg src=\"https://i.ibb.co/J2xvB1y/Screenshot-2024-05-11-at-00-24-52.png\" alt=\"Screenshot\" style=\"width:100%;\"\u003e\n\u003c/a\u003e\n\n### Example Recommendation\nIn order to improve database performance and scalability, here are some suggestions below:\n\n1. Indexing: Effective database indexing can significantly speed up query performance. For your query, consider adding a combined (composite) index on `product_id`, `price`, and `discount_total`. This index would work well because the where clause covers all these columns.\n\n```sql\nCREATE INDEX idx_product_prices\nON product_prices (product_id, price, discount_total);\n```\n(Note: The order of the columns in the index might depend on the selectivity of the columns and the data distribution. Therefore, you might have to reorder them depending on your specific situation.)\n\n2. Data Types: Ensure that the values being compared are of appropriate data types. Comparing or converting inappropriate data types at run time will slow down the search. It appears that you're using string comparisons ('1') for `product_id`, `price`, and `discount_total` which are likely numerical columns. Remove the quotes for these where clause conditions.\n\nUpdated Query:\n```sql\nSELECT COUNT(*) AS aggregate\nFROM product_prices\nWHERE product_id = 1\nAND price = 0\nAND discount_total \u003e 0;\n```\n3. ANALYZE: Another practice to improve query performance could be running the `ANALYZE` command. This command collects statistics about the contents of tables in the database, and stores the results in the pg_statistic system catalog. Subsequently, the query planner uses these statistics to help determine the most efficient execution plans for queries.\n\n```sql\nANALYZE product_prices;\n```\n\nRemember to periodically maintain your index to keep up with the CRUD operations that could lead to index fragmentation. Depending on your DBMS, you might want to REBUILD or REORGANIZE your indices.\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Roadmap\n\n- [ ] Create a documentation page.\n- [ ] Begin development of version 2.\n- [ ] Auto Indexer (Premium Feature)\n- [ ] Create a FilamentPHP plugin.\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Halil Cosdu](https://github.com/halilcosdu)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalilcosdu%2Flaravel-slower","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhalilcosdu%2Flaravel-slower","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalilcosdu%2Flaravel-slower/lists"}