Skip to content

Commit

Permalink
cache graphql edge counts. #274
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed May 16, 2019
1 parent 320e7d6 commit 74d2535
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ gem 'git', '~> 1.5'
gem 'graphql', '~> 1.9', '>= 1.9.4'
gem 'graphql-errors', '~> 0.3.0'
gem 'graphql-batch', '~> 0.4.0'
gem 'graphql-cache', '~> 0.6.0'
gem 'graphql-cache', '~> 0.6.0', git: "https://github.com/stackshareio/graphql-cache"

group :development, :test do
gem 'rspec-rails', '~> 3.8', '>= 3.8.2'
Expand Down
11 changes: 8 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
GIT
remote: https://github.com/stackshareio/graphql-cache
revision: 3c3f378ab8061326537ff6be203f6fd46fdf0acd
specs:
graphql-cache (0.6.0)
graphql (~> 1, > 1.8)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -236,8 +243,6 @@ GEM
graphql-batch (0.4.0)
graphql (>= 1.3, < 2)
promise.rb (~> 0.7.2)
graphql-cache (0.6.0)
graphql (~> 1, > 1.8)
graphql-errors (0.3.0)
graphql (>= 1.6.0, < 2)
haml (5.0.4)
Expand Down Expand Up @@ -568,7 +573,7 @@ DEPENDENCIES
git (~> 1.5)
graphql (~> 1.9, >= 1.9.4)
graphql-batch (~> 0.4.0)
graphql-cache (~> 0.6.0)
graphql-cache (~> 0.6.0)!
graphql-errors (~> 0.3.0)
iso8601 (~> 0.9.0)
json (~> 1.8, >= 1.8.5)
Expand Down
5 changes: 3 additions & 2 deletions app/graphql/types/client_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

class ClientConnectionWithMetaType < BaseConnection
edge_type(ClientEdgeType)

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
Expand Down
5 changes: 3 additions & 2 deletions app/graphql/types/funder_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

class FunderConnectionWithMetaType < BaseConnection
edge_type(FunderEdgeType)

field :total_count, Integer, null: false
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
args = object.arguments
Expand Down
5 changes: 3 additions & 2 deletions app/graphql/types/funder_dataset_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

class FunderDatasetConnectionWithMetaType < BaseConnection
edge_type(EventDataEdgeType, edge_class: EventDataEdge)

field :total_count, Integer, null: false
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, obj_id: object.parent[:id], citation_type: "Dataset-Funder").dig(:meta, "total").to_i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

class FunderPublicationConnectionWithMetaType < BaseConnection
edge_type(EventDataEdgeType, edge_class: EventDataEdge)

field :total_count, Integer, null: false
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, obj_id: object.parent[:id], citation_type: "Funder-JournalArticle").dig(:meta, "total").to_i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

class FunderSoftwareConnectionWithMetaType < BaseConnection
edge_type(EventDataEdgeType, edge_class: EventDataEdge)

field :total_count, Integer, null: false
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, obj_id: object.parent[:id], citation_type: "Funder-SoftwareSourceCode").dig(:meta, "total").to_i
Expand Down
6 changes: 2 additions & 4 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ class QueryType < BaseObject
end

def providers(query: nil)
ids = Provider.query(query, page: { number: 1, size: 250 }).results.to_a.map { |p| p.uid }
ElasticsearchLoader.for(Provider).load_many(ids)
Provider.query(query, page: { number: 1, size: 250 }).records.to_a
end

field :provider, ProviderType, null: false do
Expand All @@ -25,8 +24,7 @@ def provider(id:)
end

def clients(query: nil, year: nil, software: nil)
ids = Client.query(query, year: year, software: software, page: { number: 1, size: 2000 }).results.to_a.map { |p| p.uid }
ElasticsearchLoader.for(Client).load_many(ids)
Client.query(query, year: year, software: software, page: { number: 1, size: 2000 }).records.to_a
end

field :client, ClientType, null: false do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

class ResearcherDatasetConnectionWithMetaType < BaseConnection
edge_type(EventDataEdgeType, edge_class: EventDataEdge)

field :total_count, Integer, null: false
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, obj_id: https_to_http(object.parent[:id]), citation_type: "Dataset-Person").dig(:meta, "total").to_i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

class ResearcherPublicationConnectionWithMetaType < BaseConnection
edge_type(EventDataEdgeType, edge_class: EventDataEdge)

field :total_count, Integer, null: false
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, obj_id: https_to_http(object.parent[:id]), citation_type: "Person-ScholarlyArticle").dig(:meta, "total").to_i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

class ResearcherSoftwareConnectionWithMetaType < BaseConnection
edge_type(EventDataEdgeType, edge_class: EventDataEdge)

field :total_count, Integer, null: false
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, obj_id: https_to_http(object.parent[:id]), citation_type: "Person-SoftwareSourceCode").dig(:meta, "total").to_i
Expand Down

0 comments on commit 74d2535

Please sign in to comment.