Skip to content

Commit

Permalink
[5.x] Blink augmentation of asset fields with max_items: 1 (#10580)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell authored Aug 7, 2024
1 parent 4f63028 commit a033f0b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Fieldtypes/Assets/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Statamic\Exceptions\AssetContainerNotFoundException;
use Statamic\Facades\Asset;
use Statamic\Facades\AssetContainer;
use Statamic\Facades\Blink;
use Statamic\Facades\GraphQL;
use Statamic\Facades\Scope;
use Statamic\Fields\Fieldtype;
Expand Down Expand Up @@ -166,6 +167,12 @@ public function augment($values)
{
$values = Arr::wrap($values);

$single = $this->config('max_files') === 1;

if ($single && Blink::has($key = 'assets-augment-'.json_encode($values))) {
return Blink::get($key);
}

$ids = collect($values)
->map(fn ($value) => $this->container()->handle().'::'.$value)
->all();
Expand All @@ -174,7 +181,7 @@ public function augment($values)

$query = new OrderedQueryBuilder($query, $ids);

return $this->config('max_files') === 1 ? $query->first() : $query;
return $single ? Blink::once($key, fn () => $query->first()) : $query;
}

public function shallowAugment($values)
Expand Down

0 comments on commit a033f0b

Please sign in to comment.