Skip to content

Commit

Permalink
Refactor if/else statement
Browse files Browse the repository at this point in the history
  • Loading branch information
MattFenelon committed Sep 19, 2024
1 parent e42b9f8 commit a653122
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions lib/graphiti/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,25 @@ def resolve_sideloads(results)
end

def future_resolve
if @query.zero_results?
Concurrent::Promises.fulfilled_future([], self.class.global_thread_pool_executor)
else
resolved = broadcast_data { |payload|
@object = @resource.before_resolve(@object, @query)
payload[:results] = @resource.resolve(@object)
payload[:results]
}
resolved.compact!
assign_serializer(resolved)
yield resolved if block_given?
@opts[:after_resolve]&.call(resolved)
sideloaded = @query.parents.any?
close_adapter = Graphiti.config.concurrency && sideloaded
if close_adapter
@resource.adapter.close
end
return Concurrent::Promises.fulfilled_future([], self.class.global_thread_pool_executor) if @query.zero_results?

future_resolve_sideloads(resolved)
.then_on(self.class.global_thread_pool_executor, resolved) { resolved }
resolved = broadcast_data { |payload|
@object = @resource.before_resolve(@object, @query)
payload[:results] = @resource.resolve(@object)
payload[:results]
}
resolved.compact!
assign_serializer(resolved)
yield resolved if block_given?
@opts[:after_resolve]&.call(resolved)
sideloaded = @query.parents.any?
close_adapter = Graphiti.config.concurrency && sideloaded
if close_adapter
@resource.adapter.close
end

future_resolve_sideloads(resolved)
.then_on(self.class.global_thread_pool_executor, resolved) { resolved }
end

def parent_resource
Expand Down

0 comments on commit a653122

Please sign in to comment.