Skip to content

Commit

Permalink
Add adapter close on the same thread
Browse files Browse the repository at this point in the history
Rails assigns a connection to a thread so the close call has to happen
on that same thread for the thread's connection to be closed.
  • Loading branch information
MattFenelon committed May 10, 2024
1 parent 3db3856 commit 7694ee4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/graphiti/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def resolve
def resolve_sideloads(results)
return if results == []

concurrent = Graphiti.config.concurrency

promises = @query.sideloads.filter_map do |name, q|
sideload = @resource.class.sideload(name)
next if sideload.nil? || sideload.shared_remote?
Expand All @@ -66,11 +68,9 @@ def resolve_sideloads(results)
Graphiti.config.before_sideload&.call(graphiti_context)
Graphiti.context = graphiti_context
results = sideload.resolve(results, q, parent_resource)
@resource.adapter.close if concurrent
if results.is_a?(Concurrent::Promises::Future)
results.then_on(self.class.global_thread_pool_executor) do
# TODO: will this always run?
@resource.adapter.close
end
results
else
Concurrent::Promises.fulfilled_future(results, self.class.global_thread_pool_executor)
end
Expand Down

0 comments on commit 7694ee4

Please sign in to comment.