Skip to content
Closed
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
5 changes: 4 additions & 1 deletion lib/private/DB/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ public function insertIfNotExist($table, $input, ?array $compare = null) {
$query .= ' HAVING COUNT(*) = 0';

try {
return $this->conn->executeUpdate($query, $inserts);
$this->conn->beginTransaction();
$rows = $this->conn->executeUpdate($query, $inserts);
Copy link
Member

Choose a reason for hiding this comment

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

would the transaction stay open if this line throws? I think an explicit rollback is needed, at least for postgres

Copy link
Member

Choose a reason for hiding this comment

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

could alternatively use the atomic() helper from OCP\AppFramework\Db\TTransactional perhaps?

$this->conn->commit();
return $rows;
} catch (UniqueConstraintViolationException $e) {
// This exception indicates a concurrent insert happened between
// the insert and the sub-select in the insert, which is safe to ignore.
Expand Down
Loading