orderBy('id')->limit(2000)->pluck('id'); if ($ids->isEmpty()) return; DB::table('admin_realtime_events')->insert([ 'resource' => self::RESOURCE, 'resource_id' => '1', 'action' => 'updated', 'source' => 'bot-28', 'created_at' => now('Asia/Shanghai')->format('Y-m-d H:i:s'), ]); // Delete only the visible rows. A long transaction can commit a lower ID later. $buffer->whereIntegerInRaw('id', $ids->all())->delete(); } }