Skip to content

Commit

Permalink
performance improvements with caching and using elasticsearch results.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed May 19, 2019
1 parent 7ed7b17 commit a4bb6d8
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 15 deletions.
6 changes: 1 addition & 5 deletions app/graphql/elasticsearch_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion app/graphql/types/client_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/graphql/types/dataset_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/graphql/types/organization_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions app/graphql/types/provider_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion app/graphql/types/publication_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/graphql/types/software_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a4bb6d8

Please sign in to comment.