Skip to content

Commit 58dec2d

Browse files
committed
Merge pull request #224 from ruby-rdf/feature/transaction-atom
Make `Transaction#execute` more atomic
2 parents 8a6e86e + 42b67bb commit 58dec2d

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

lib/rdf/transaction.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,21 @@ def readable?
130130
def execute(repository, options = {})
131131
before_execute(repository, options) if respond_to?(:before_execute)
132132

133-
deletes.each_statement do |statement|
134-
statement = statement.dup
133+
dels = deletes.map do |s|
134+
statement = s.dup
135135
statement.graph_name ||= graph_name
136-
repository.delete(statement)
136+
statement
137137
end
138138

139-
inserts.each_statement do |statement|
140-
statement = statement.dup
139+
ins = inserts.map do |s|
140+
statement = s.dup
141141
statement.graph_name ||= graph_name
142-
repository.insert(statement)
142+
statement
143143
end
144-
144+
145+
repository.delete(*dels) unless dels.empty?
146+
repository.insert(*ins) unless ins.empty?
147+
145148
after_execute(repository, options) if respond_to?(:after_execute)
146149
self
147150
end

0 commit comments

Comments
 (0)