dont create empty filecache extended rows
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
2165f10aaf
commit
43fa746ad9
|
@ -292,14 +292,16 @@ class Cache implements ICache {
|
|||
if ($builder->execute()) {
|
||||
$fileId = $builder->getLastInsertId();
|
||||
|
||||
$query = $this->getQueryBuilder();
|
||||
$query->insert('filecache_extended');
|
||||
if (count($extensionValues)) {
|
||||
$query = $this->getQueryBuilder();
|
||||
$query->insert('filecache_extended');
|
||||
|
||||
$query->setValue('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT));
|
||||
foreach ($extensionValues as $column => $value) {
|
||||
$query->setValue($column, $query->createNamedParameter($value));
|
||||
$query->setValue('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT));
|
||||
foreach ($extensionValues as $column => $value) {
|
||||
$query->setValue($column, $query->createNamedParameter($value));
|
||||
}
|
||||
$query->execute();
|
||||
}
|
||||
$query->execute();
|
||||
|
||||
$this->eventDispatcher->dispatch(CacheInsertEvent::class, new CacheInsertEvent($this->storage, $file, $fileId));
|
||||
return $fileId;
|
||||
|
@ -357,21 +359,33 @@ class Cache implements ICache {
|
|||
}
|
||||
|
||||
if (count($extensionValues)) {
|
||||
$query = $this->getQueryBuilder();
|
||||
$query->update('filecache_extended')
|
||||
->whereFileId($id)
|
||||
->andWhere($query->expr()->orX(...array_map(function ($key, $value) use ($query) {
|
||||
return $query->expr()->orX(
|
||||
$query->expr()->neq($key, $query->createNamedParameter($value)),
|
||||
$query->expr()->isNull($key)
|
||||
);
|
||||
}, array_keys($extensionValues), array_values($extensionValues))));
|
||||
try {
|
||||
$query = $this->getQueryBuilder();
|
||||
$query->insert('filecache_extended');
|
||||
|
||||
foreach ($extensionValues as $key => $value) {
|
||||
$query->set($key, $query->createNamedParameter($value));
|
||||
$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)
|
||||
->andWhere($query->expr()->orX(...array_map(function ($key, $value) use ($query) {
|
||||
return $query->expr()->orX(
|
||||
$query->expr()->neq($key, $query->createNamedParameter($value)),
|
||||
$query->expr()->isNull($key)
|
||||
);
|
||||
}, array_keys($extensionValues), array_values($extensionValues))));
|
||||
|
||||
foreach ($extensionValues as $key => $value) {
|
||||
$query->set($key, $query->createNamedParameter($value));
|
||||
}
|
||||
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
$path = $this->getPathById($id);
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue