dont create empty filecache extended rows

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2019-10-31 14:22:32 +01:00
parent 2165f10aaf
commit 43fa746ad9
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
2 changed files with 41 additions and 20 deletions

View File

@ -292,6 +292,7 @@ class Cache implements ICache {
if ($builder->execute()) {
$fileId = $builder->getLastInsertId();
if (count($extensionValues)) {
$query = $this->getQueryBuilder();
$query->insert('filecache_extended');
@ -300,6 +301,7 @@ class Cache implements ICache {
$query->setValue($column, $query->createNamedParameter($value));
}
$query->execute();
}
$this->eventDispatcher->dispatch(CacheInsertEvent::class, new CacheInsertEvent($this->storage, $file, $fileId));
return $fileId;
@ -357,6 +359,17 @@ class Cache implements ICache {
}
if (count($extensionValues)) {
try {
$query = $this->getQueryBuilder();
$query->insert('filecache_extended');
$query->setValue('fileid', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT));
foreach ($extensionValues as $column => $value) {
$query->setValue($column, $query->createNamedParameter($value));
}
$query->execute();
} catch (UniqueConstraintViolationException $e) {
$query = $this->getQueryBuilder();
$query->update('filecache_extended')
->whereFileId($id)
@ -373,6 +386,7 @@ class Cache implements ICache {
$query->execute();
}
}
$path = $this->getPathById($id);
// path can still be null if the file doesn't exist

View File

@ -718,7 +718,7 @@ class CacheTest extends \Test\TestCase {
$data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'text/plain', 'metadata_etag' => 'foo'];
$this->cache->put("foo3", $data);
$data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'text/plain'];
$this->cache->put("foo4", $data);
$id4 = $this->cache->put("foo4", $data);
$entry = $this->cache->get($id1);
$this->assertEquals(20, $entry->getCreationTime());
@ -766,6 +766,13 @@ class CacheTest extends \Test\TestCase {
$this->assertEquals(20, $entries[0]->getCreationTime());
$this->assertEquals(25, $entries[0]->getUploadTime());
$this->assertEquals(null, $entries[0]->getMetadataEtag());
$this->cache->update($id4, ['upload_time' => 25]);
$entry = $this->cache->get($id4);
$this->assertEquals(0, $entry->getCreationTime());
$this->assertEquals(25, $entry->getUploadTime());
$this->assertEquals(null, $entry->getMetadataEtag());
}
protected function tearDown() {