From a6531228fd0a0e9b210bc37b70e442b0fbe6a247 Mon Sep 17 00:00:00 2001 From: Matthew Fenelon Date: Thu, 19 Sep 2024 16:16:42 +0100 Subject: [PATCH] Refactor if/else statement --- lib/graphiti/scope.rb | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/lib/graphiti/scope.rb b/lib/graphiti/scope.rb index fc29ceb9..d837ae8b 100644 --- a/lib/graphiti/scope.rb +++ b/lib/graphiti/scope.rb @@ -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