Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/Board.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,15 @@ protected function setUp(): void
*/
public function getViewData(): array
{
// Batch all column counts in a single query
$allCounts = $this->getBatchedBoardRecordCounts();
$batchedRecords = $this->getBatchedBoardRecords();

// Build columns data using new concerns
$columns = [];

foreach ($this->getColumns() as $column) {
$columnId = $column->getName();

// Get formatted records
$records = $this->getBoardRecords($columnId);
$records = $batchedRecords[$columnId] ?? new \Illuminate\Database\Eloquent\Collection;
$formattedRecords = $records->map(fn ($record) => $this->formatBoardRecord($record))->toArray();

$columns[$columnId] = [
Expand Down
49 changes: 49 additions & 0 deletions src/Concerns/HasBoardRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,55 @@ public function getBatchedBoardRecordCounts(): array
->toArray();
}

/**
* Get records for ALL columns in a single query, partitioned in PHP.
*
* @return array<string, Collection>
*/
public function getBatchedBoardRecords(): array
{
$query = $this->getQuery();

if (! $query) {
return [];
}

$statusField = $this->getColumnIdentifierAttribute();
$positionField = $this->getPositionIdentifierAttribute();
$limit = $this->getCardsPerColumn();
$livewire = $this->getLivewire();

$baseQuery = clone $query;

if ($livewire->getTable()->isFilterable() || $livewire->hasTableSearch()) {
$baseQuery = clone $livewire->getFilteredTableQuery();
}

$keyName = $baseQuery->getModel()->getKeyName();
$columnIds = collect($this->getColumns())->map(fn ($col) => $col->getName())->all();

$allRecords = (clone $baseQuery)
->whereIn($statusField, $columnIds)
->orderBy($positionField, 'asc')
->orderBy($keyName, 'asc')
->get();
Comment on lines +178 to +182
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The position field ordering is applied unconditionally, but the original getBoardRecords() method (line 90) checks if the position field exists using modelHasColumn() before ordering. This could cause SQL errors if the position field doesn't exist in the table. Add a check similar to the one in getBoardRecords():

if ($positionField && $this->modelHasColumn($baseQuery->getModel(), $positionField)) {
    $allRecords = (clone $baseQuery)
        ->whereIn($statusField, $columnIds)
        ->orderBy($positionField, 'asc')
        ->orderBy($keyName, 'asc')
        ->get();
} else {
    $allRecords = (clone $baseQuery)
        ->whereIn($statusField, $columnIds)
        ->orderBy($keyName, 'asc')
        ->get();
}
Suggested change
$allRecords = (clone $baseQuery)
->whereIn($statusField, $columnIds)
->orderBy($positionField, 'asc')
->orderBy($keyName, 'asc')
->get();
if ($positionField && $this->modelHasColumn($baseQuery->getModel(), $positionField)) {
$allRecords = (clone $baseQuery)
->whereIn($statusField, $columnIds)
->orderBy($positionField, 'asc')
->orderBy($keyName, 'asc')
->get();
} else {
$allRecords = (clone $baseQuery)
->whereIn($statusField, $columnIds)
->orderBy($keyName, 'asc')
->get();
}

Copilot uses AI. Check for mistakes.

$partitioned = [];

foreach ($columnIds as $columnId) {
$columnLimit = property_exists($livewire, 'columnCardLimits')
? ($livewire->columnCardLimits[$columnId] ?? $limit)
: $limit;

$partitioned[$columnId] = $allRecords
->filter(fn ($record) => (string) data_get($record, $statusField) === (string) $columnId)
->take($columnLimit)
->values();
}

return $partitioned;
}

/**
* Format a record for display with Infolist entries.
*/
Expand Down