Skip to content

A free open source IT asset/license management system

Cap the calendar backfill to 2000 rows

snipe8588df989a64
diff --git a/database/migrations/2026_08_13_160100_backfill_calendar_events_from_existing_sources.php b/database/migrations/2026_08_13_160100_backfill_calendar_events_from_existing_sources.php
index 38e669408e..2f9a5735a4 100644
--- a/database/migrations/2026_08_13_160100_backfill_calendar_events_from_existing_sources.php
+++ b/database/migrations/2026_08_13_160100_backfill_calendar_events_from_existing_sources.php
@@ -17,6 +17,13 @@ use Illuminate\Database\Migrations\Migration;
* populates the index so those existing records show up on the
* calendar without waiting for a manual save on each one.
*
+ * Capped at the most-recent 2000 rows per source (ordered by primary
+ * key desc). Large installs with a decade of audit / maintenance /
+ * checkout history would otherwise grind through every historical
+ * row during upgrade to populate a calendar view most users only use
+ * for recent and upcoming events. Admins who want the full backlog
+ * run snipeit:reconcile-calendar-events after the upgrade completes.
+ *
* Duplicates snipeit:reconcile-calendar-events's sync logic on
* purpose - the command is meant to be re-runnable on demand later,
* this migration is the one-time seed at deploy time. Kept small
@@ -42,15 +49,19 @@ return new class extends Migration
protected function backfillSource(string $sourceClass): void
{
+ $instance = new $sourceClass;
+ $keyName = $instance->getKeyName();
+
$sourceClass::query()
->when(
in_array(SoftDeletes::class, class_uses_recursive($sourceClass), true),
fn ($q) => $q->withTrashed(),
)
- ->chunkById(500, function ($rows) {
- foreach ($rows as $row) {
- $row->forceSyncCalendarEvents();
- }
+ ->orderByDesc($keyName)
+ ->limit(2000)
+ ->get()
+ ->each(function ($row) {
+ $row->forceSyncCalendarEvents();
});
}