Skip to content

Commit 42b67bb

Browse files
author
Tom Johnson
committed
Make Transaction#execute more atomic
Executing a transaction individually called `#delete` or `#insert` for each statement in the changeset. This prevents using the features of `Repositories` with a more efficient implementation of `#insert/delete_statements`. The patch fixes this (partially) by calling `#delete` and `#insert` only once each for each execution, making executions faster for some repositories and closer to being properly atomic. A caveat, of course, is that there are still two upstream requests required for each "transaction". We may regard that as okay, with @bendiken's planned 2.0 changes to transaction, and seeing this interface as a changeset. Another option is to implement `#delete_insert(deletes, inserts)` in `RDF::Mutable`; the base implementation could simply be to call `#delete` and `#insert` in turn, but `Repository` specializations could handle them as a single request. Thoughts?
1 parent 6fefc1e commit 42b67bb

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)