diff --git a/app/graphql/types/data_catalog_type.rb b/app/graphql/types/data_catalog_type.rb index 8eb077df6..526f49146 100644 --- a/app/graphql/types/data_catalog_type.rb +++ b/app/graphql/types/data_catalog_type.rb @@ -145,24 +145,30 @@ def datasets(**args) end def view_count - if response.results.total.positive? - aggregate_count(response.response.aggregations.views.buckets) + args = { first: 0 } + @r = response(args) if @r.nil? + if @r.results.total.positive? + aggregate_count(@r.response.aggregations.views.buckets) else 0 end end def download_count - if response.results.total.positive? - aggregate_count(response.response.aggregations.downloads.buckets) + args = { first: 0 } + @r = response(args) if @r.nil? + if @r.results.total.positive? + aggregate_count(@r.response.aggregations.downloads.buckets) else 0 end end def citation_count - if response.results.total.positive? - aggregate_count(response.response.aggregations.citations.buckets) + args = { first: 0 } + @r = response(args) if @r.nil? + if @r.results.total.positive? + aggregate_count(@r.response.aggregations.citations.buckets) else 0 end diff --git a/app/graphql/types/funder_type.rb b/app/graphql/types/funder_type.rb index 5988abdf1..e46d23cdd 100644 --- a/app/graphql/types/funder_type.rb +++ b/app/graphql/types/funder_type.rb @@ -218,20 +218,20 @@ def works(**args) def view_count args = { first: 0 } - r = response(args) - r.response.aggregations.view_count.value.to_i + @r = response(args) if @r.nil? + @r.response.aggregations.view_count.value.to_i end def download_count args = { first: 0 } - r = response(args) - r.response.aggregations.download_count.value.to_i + @r = response(args) if @r.nil? + @r.response.aggregations.download_count.value.to_i end def citation_count args = { first: 0 } - r = response(args) - r.response.aggregations.citation_count.value.to_i + @r = response(args) if @r.nil? + @r.response.aggregations.citation_count.value.to_i end def response(**args) diff --git a/app/graphql/types/member_type.rb b/app/graphql/types/member_type.rb index 970e98004..6c0ba9ed2 100644 --- a/app/graphql/types/member_type.rb +++ b/app/graphql/types/member_type.rb @@ -305,9 +305,9 @@ def repositories(**args) def view_count args = { first: 0 } - r = response(args) - if r.results.total.positive? - aggregate_count(r.response.aggregations.views.buckets) + @r = response(args) if @r.nil? + if @r.results.total.positive? + aggregate_count(@r.response.aggregations.views.buckets) else 0 end @@ -315,9 +315,9 @@ def view_count def download_count args = { first: 0 } - r = response(args) - if r.results.total.positive? - aggregate_count(r.response.aggregations.downloads.buckets) + @r = response(args) if @r.nil? + if @r.results.total.positive? + aggregate_count(@r.response.aggregations.downloads.buckets) else 0 end @@ -325,9 +325,9 @@ def download_count def citation_count args = { first: 0 } - r = response(args) - if r.results.total.positive? - aggregate_count(r.response.aggregations.citations.buckets) + @r = response(args) if @r.nil? + if @r.results.total.positive? + aggregate_count(@r.response.aggregations.citations.buckets) else 0 end diff --git a/app/graphql/types/organization_type.rb b/app/graphql/types/organization_type.rb index 687127a6e..ed5b15830 100644 --- a/app/graphql/types/organization_type.rb +++ b/app/graphql/types/organization_type.rb @@ -331,20 +331,20 @@ def people(**args) def view_count args = { first: 0 } - r = response(args) - r.response.aggregations.view_count.value.to_i + @r = response(args) if @r.nil? + @r.response.aggregations.view_count.value.to_i end def download_count args = { first: 0 } - r = response(args) - r.response.aggregations.download_count.value.to_i + @r = response(args) if @r.nil? + @r.response.aggregations.download_count.value.to_i end def citation_count args = { first: 0 } - r = response(args) - r.response.aggregations.citation_count.value.to_i + @r = response(args) if @r.nil? + @r.response.aggregations.citation_count.value.to_i end def response(**args) diff --git a/app/graphql/types/repository_type.rb b/app/graphql/types/repository_type.rb index b46aeefe1..6012d98c6 100644 --- a/app/graphql/types/repository_type.rb +++ b/app/graphql/types/repository_type.rb @@ -275,20 +275,20 @@ def prefixes(**args) def view_count args = { first: 0 } - r = response(args) - r.response.aggregations.view_count.value.to_i + @r = response(args) if @r.nil? + @r.response.aggregations.view_count.value.to_i end def download_count args = { first: 0 } - r = response(args) - r.response.aggregations.download_count.value.to_i + @r = response(args) if @r.nil? + @r.response.aggregations.download_count.value.to_i end def citation_count args = { first: 0 } - r = response(args) - r.response.aggregations.citation_count.value.to_i + @r = response(args) if @r.nil? + @r.response.aggregations.citation_count.value.to_i end def response(**args)