Skip to content

Commit

Permalink
misc other fixes for loading openalex snapshot version
Browse files Browse the repository at this point in the history
  • Loading branch information
alepbloyd committed Jan 16, 2025
1 parent 1482675 commit 0d8490f
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 48 deletions.
1 change: 1 addition & 0 deletions rails/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ WORKDIR /rails

# Set production environment
ENV RAILS_ENV="production" \
RAILS_MASTER_KEY=$RAILS_MASTER_KEY \
BUNDLE_DEPLOYMENT="1" \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_WITHOUT="development"
Expand Down
Empty file added rails/README.md
Empty file.
15 changes: 14 additions & 1 deletion rails/app/graphql/types/author_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,24 @@ class AuthorType < Types::BaseObject
field :last_known_institution, String
field :works_api_url, String

field :authors_ids, Types::AuthorsIdsType
field :works, [Types::WorkType]
def works
object.works
end

field :authors_ids, Types::AuthorsIdsType
def authors_ids
object.authors_ids
end

field :institutions, [Types::InstitutionType]
def institutions
object.institutions.uniq # move this to the Author model probably
end

field :authors_counts_by_year, [Types::AuthorsCountsByYearType]
def authors_counts_by_year
object.authors_counts_by_year
end
end
end

This file was deleted.

28 changes: 17 additions & 11 deletions rails/app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,24 @@ def nodes(ids:)
ids.map { |id| context.schema.object_from_id(id, context) }
end

field :institution_by_openalex_id,
Types::InstitutionType,
null: true,
description: 'Fetches an institution by institution_openalex_id' do
argument :institution_openalex_id, String, required: true
end
def institution(institution_openalex_id:)
Institution.find_by(institution_openalex_id: institution_openalex_id)
end
# need to index institutions by openalex id
# field :institution_by_openalex_id,
# Types::InstitutionType,
# null: true,
# description: 'Fetches an institution by institution_openalex_id' do
# argument :institution_openalex_id, String, required: true
# end
# def institution_by_openalex_id(institution_openalex_id:)
# Institution.find_by(institution_openalex_id: institution_openalex_id)
# end

field :institution_by_ror,
Types::InstitutionType,
null: true,
description: 'Fetches an institution by ROR' do
argument :ror, String, required: true
end
def institution(institution_openalex_id:)
def institution_by_ror(ror:)
Institution.find_by(ror: ror)
end

Expand All @@ -63,7 +64,12 @@ def author_by_openalex_id(author_openalex_id:)
argument :orcid, String, required: true
end
def author_by_orcid(orcid:)
Author.find_by(orcid: orcid)
# do some error handling for invalid entries
if "https://orcid.org/".in? orcid
Author.find_by(orcid: orcid)
else
Author.find_by(orcid: "https://orcid.org/" + orcid)
end
end

# work entry points
Expand Down
6 changes: 5 additions & 1 deletion rails/app/graphql/types/topic_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ class TopicType < Types::BaseObject
field :openalex_domain_id, Integer
field :openalex_domain_display_name, String
field :description, String
field :keywords, String
field :works_api_url, String
field :wikipedia_id, String
field :works_count, Integer
field :cited_by_count, Integer
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false

field :keywords, [String]
def keywords
object.keywords
end
end
end
5 changes: 5 additions & 0 deletions rails/app/graphql/types/work_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,10 @@ def works_biblio
def topics
object.topics
end

field :works_ids, Types::WorksIdsType
def works_ids
object.works_ids
end
end
end
14 changes: 0 additions & 14 deletions rails/app/graphql/types/works_authorship_type.rb

This file was deleted.

3 changes: 3 additions & 0 deletions rails/app/models/author.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ class Author < ApplicationRecord
has_one :authors_ids,
primary_key: :author_openalex_id,
foreign_key: :author_openalex_id

has_many :authors_counts_by_year,
primary_key: :author_openalex_id,
foreign_key: :author_openalex_id

has_many :works_authorships,
primary_key: :author_openalex_id,
foreign_key: :author_openalex_id

has_many :institutions, through: :works_authorships
has_many :works, through: :works_authorships
end
6 changes: 3 additions & 3 deletions rails/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ default: &default
encoding: unicode
username: bookworm
# password: <%= ENV["POSTGRES_PASSWORD"] %>
password: password
pool: 5

development:
host: localhost
<<: *default
host: localhost
password: password
database: bookworm_development

test:
host: localhost
<<: *default
host: localhost
database: bookworm_test
password: password

Expand Down
2 changes: 2 additions & 0 deletions rails/config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require 'active_support/core_ext/integer/time'

Rails.application.configure do
config.hosts << 'ec2-34-215-107-32.us-west-2.compute.amazonaws.com:3000'
config.hosts << 'ec2-35-94-47-108.us-west-2.compute.amazonaws.com:3000'
config.log_level = :debug
# Settings specified here will take precedence over those in config/application.rb.

Expand Down
8 changes: 4 additions & 4 deletions rails/db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
# end

# # create initial work node
# BookWormApiSchema.execute(
# BookWormSchema.execute(
# sign_in_mutation,
# variables: {
# email: user_1.email,
Expand All @@ -107,7 +107,7 @@
# )

# work_node_response =
# BookWormApiSchema.execute(
# BookWormSchema.execute(
# create_work_node_mutation,
# variables: {
# investigationId: investigation_1.id.to_s,
Expand All @@ -122,7 +122,7 @@
# work_node_response['data']['createWorkNode']['work']['openalexId']

# response =
# BookWormApiSchema.execute(
# BookWormSchema.execute(
# add_references_mutation,
# variables: {
# openalexId: work_node_openalex_id,
Expand All @@ -134,7 +134,7 @@
# ).to_h

# investigation_response =
# BookWormApiSchema.execute(
# BookWormSchema.execute(
# investigation_query,
# variables: {
# id: investigation_1.id
Expand Down
2 changes: 1 addition & 1 deletion rails/lib/tasks/load_works.rake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace :data_import do
language: row[12]
}

if works.count >= 5000
if works.count >= 10000
Work.insert_all(works)
works = []
end
Expand Down
2 changes: 1 addition & 1 deletion rails/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0d8490f

Please sign in to comment.