3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-08-18 11:15:42 +00:00

Fixed #9430 - make next audit date sortable

This commit is contained in:
snipe
2026-07-30 09:04:09 +01:00
parent c94402dc98
commit 01fb459dd2
4 changed files with 97 additions and 2 deletions

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* Speeds up two query paths that sort/filter on assets.next_audit_date:
*
* - Audit report sort (#9430) via Actionlog::scopeOrderByAssetNextAuditDate,
* which leftJoins assets on the polymorphic item_id/item_type and
* orders by next_audit_date. Without an index, larger installs
* filesort the entire filtered set per paged click.
* - SendUpcomingAuditReport's dueOrOverdueForAudit scope, which
* filters assets by next_audit_date within a window. Runs
* nightly via the scheduler; on installs with 100k+ assets the
* full-scan cost showed up in slow-query logs.
*/
return new class extends Migration
{
public function up(): void
{
Schema::table('assets', function (Blueprint $table) {
$table->index('next_audit_date', 'assets_next_audit_date_index');
});
}
public function down(): void
{
Schema::table('assets', function (Blueprint $table) {
$table->dropIndex('assets_next_audit_date_index');
});
}
};