Skip to content

Commit 61fd51b

Browse files
authored
Don't blink asset-meta-exists if the file doesnt exist (#451)
1 parent ec7c78c commit 61fd51b

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/Assets/Asset.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ public function meta($key = null)
6565
return $meta;
6666
}
6767

68+
// this handles asset::make() without save()
69+
// e.g. when checking a file exists already when uploading
70+
if (! $this->disk()->exists($this->path())) {
71+
return ['data' => []];
72+
}
73+
6874
return Blink::once($this->metaCacheKey(), function () {
6975
if ($model = app('statamic.eloquent.assets.model')::where([
7076
'container' => $this->containerHandle(),
@@ -101,7 +107,7 @@ public function metaExists()
101107
'container' => $this->containerHandle(),
102108
'folder' => $this->folder(),
103109
'basename' => $this->basename(),
104-
])->count() > 0;
110+
])->exists();
105111
});
106112
}
107113

src/Assets/AssetContainerContents.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function add($path)
136136
$this->add($dir);
137137
}
138138

139-
$this->folders->push(['path' => $path]);
139+
$this->folders->push(['path' => $path, 'type' => 'dir']);
140140

141141
return $this;
142142
}

tests/Assets/AssetTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,21 @@ public function saving_an_asset_clears_the_eloquent_blink_cache()
5454

5555
$this->assertFalse(Facades\Blink::has("eloquent-asset-{$asset->id()}"));
5656
}
57+
58+
#[Test]
59+
public function making_an_asset_without_saving_doesnt_make_a_meta_exists_blink_cache_entry()
60+
{
61+
Facades\Blink::flush();
62+
63+
$this->assertCount(0, Facades\Blink::allStartingWith('eloquent-asset-meta-exists-'));
64+
65+
Storage::disk('test')->put('test.jpg', '');
66+
$asset = Facades\Asset::make()->container('test')->path('test.jpg');
67+
68+
$this->assertCount(0, Facades\Blink::allStartingWith('eloquent-asset-meta-exists-'));
69+
70+
$asset->save();
71+
72+
$this->assertCount(1, Facades\Blink::allStartingWith('eloquent-asset-meta-exists-'));
73+
}
5774
}

0 commit comments

Comments
 (0)