diff --git a/app/graphql/elasticsearch_loader.rb b/app/graphql/elasticsearch_loader.rb index c62611b80..6a8714c90 100644 --- a/app/graphql/elasticsearch_loader.rb +++ b/app/graphql/elasticsearch_loader.rb @@ -6,11 +6,7 @@ def initialize(model) end def perform(ids) - if @model.name == "Doi" - @model.find_by_id(ids).results.each { |record| fulfill(record.uid, record) } - else - @model.find_by_id(ids).records.each { |record| fulfill(record.uid, record) } - end + @model.find_by_id(ids).results.each { |record| fulfill(record.uid, record) } ids.each { |id| fulfill(id, nil) unless fulfilled?(id) } end end diff --git a/app/graphql/types/client_connection_with_meta_type.rb b/app/graphql/types/client_connection_with_meta_type.rb index 4b2a78de0..16ebabc4d 100644 --- a/app/graphql/types/client_connection_with_meta_type.rb +++ b/app/graphql/types/client_connection_with_meta_type.rb @@ -7,6 +7,8 @@ class ClientConnectionWithMetaType < BaseConnection field :total_count, Integer, null: false, cache: true def total_count - object.nodes.size + args = object.arguments + + Client.query(args[:query], year: args[:year], software: args[:software], page: { number: 1, size: 0 }).results.total end end diff --git a/app/graphql/types/client_publication_connection_with_meta_type.rb b/app/graphql/types/client_publication_connection_with_meta_type.rb index 05a4aa65e..cc2b8afff 100644 --- a/app/graphql/types/client_publication_connection_with_meta_type.rb +++ b/app/graphql/types/client_publication_connection_with_meta_type.rb @@ -2,8 +2,9 @@ class ClientPublicationConnectionWithMetaType < BaseConnection edge_type(DatasetEdgeType) + field_class GraphQL::Cache::Field - field :total_count, Integer, null: false + field :total_count, Integer, null: false, cache: true def total_count args = object.arguments diff --git a/app/graphql/types/client_software_connection_with_meta_type.rb b/app/graphql/types/client_software_connection_with_meta_type.rb index a19cdee05..03e3c0537 100644 --- a/app/graphql/types/client_software_connection_with_meta_type.rb +++ b/app/graphql/types/client_software_connection_with_meta_type.rb @@ -2,8 +2,9 @@ class ClientSoftwareConnectionWithMetaType < BaseConnection edge_type(DatasetEdgeType) + field_class GraphQL::Cache::Field - field :total_count, Integer, null: false + field :total_count, Integer, null: false, cache: true def total_count args = object.arguments diff --git a/app/graphql/types/dataset_connection_with_meta_type.rb b/app/graphql/types/dataset_connection_with_meta_type.rb index 91673ab1c..90e41787f 100644 --- a/app/graphql/types/dataset_connection_with_meta_type.rb +++ b/app/graphql/types/dataset_connection_with_meta_type.rb @@ -2,8 +2,9 @@ class DatasetConnectionWithMetaType < BaseConnection edge_type(DatasetEdgeType) + field_class GraphQL::Cache::Field - field :total_count, Integer, null: false + field :total_count, Integer, null: false, cache: true def total_count args = object.arguments diff --git a/app/graphql/types/organization_connection_with_meta_type.rb b/app/graphql/types/organization_connection_with_meta_type.rb index acc127311..0abbc4323 100644 --- a/app/graphql/types/organization_connection_with_meta_type.rb +++ b/app/graphql/types/organization_connection_with_meta_type.rb @@ -2,8 +2,9 @@ class OrganizationConnectionWithMetaType < BaseConnection edge_type(OrganizationEdgeType) + field_class GraphQL::Cache::Field - field :total_count, Integer, null: false + field :total_count, Integer, null: false, cache: true def total_count args = object.arguments diff --git a/app/graphql/types/provider_connection_with_meta_type.rb b/app/graphql/types/provider_connection_with_meta_type.rb index 96a1402e4..31be1f5d1 100644 --- a/app/graphql/types/provider_connection_with_meta_type.rb +++ b/app/graphql/types/provider_connection_with_meta_type.rb @@ -2,10 +2,13 @@ class ProviderConnectionWithMetaType < BaseConnection edge_type(ProviderEdgeType) - - field :total_count, Integer, null: false + field_class GraphQL::Cache::Field + + field :total_count, Integer, null: false, cache: true def total_count - object.nodes.size + args = object.arguments + + Provider.query(args[:query], year: args[:year], page: { number: 1, size: 0 }).results.total end end diff --git a/app/graphql/types/publication_connection_with_meta_type.rb b/app/graphql/types/publication_connection_with_meta_type.rb index 70dda83e2..2309cfefd 100644 --- a/app/graphql/types/publication_connection_with_meta_type.rb +++ b/app/graphql/types/publication_connection_with_meta_type.rb @@ -2,8 +2,9 @@ class PublicationConnectionWithMetaType < BaseConnection edge_type(DatasetEdgeType) + field_class GraphQL::Cache::Field - field :total_count, Integer, null: false + field :total_count, Integer, null: false, cache: true def total_count args = object.arguments diff --git a/app/graphql/types/software_connection_with_meta_type.rb b/app/graphql/types/software_connection_with_meta_type.rb index d21d65460..a39ae7a37 100644 --- a/app/graphql/types/software_connection_with_meta_type.rb +++ b/app/graphql/types/software_connection_with_meta_type.rb @@ -2,8 +2,9 @@ class SoftwareConnectionWithMetaType < BaseConnection edge_type(DatasetEdgeType) + field_class GraphQL::Cache::Field - field :total_count, Integer, null: false + field :total_count, Integer, null: false, cache: true def total_count args = object.arguments