-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop pulling location details from graphql
This slows down the query especially in cases where there are a lot of items.
- Loading branch information
Showing
18 changed files
with
170 additions
and
404 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
module Folio | ||
Campus = Data.define(:id, :code) | ||
Campus = Data.define(:id, :code) do | ||
def self.from_dynamic(dyn) | ||
new( | ||
id: dyn.fetch('id'), | ||
code: dyn.fetch('code') | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
module Folio | ||
Location = Data.define(:id, :campus, :library, :library_id, :institution, :code, :discovery_display_name, | ||
:name, :primary_service_point_id, :details) do | ||
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength | ||
# Models a location from Folio | ||
class Location | ||
# rubocop:disable Metrics/ParameterLists | ||
def initialize(id:, campus_id:, library_id:, institution_id:, code:, discovery_display_name:, | ||
name:, primary_service_point_id:, details:) | ||
@id = id | ||
@library_id = library_id | ||
@campus_id = campus_id | ||
@institution_id = institution_id | ||
@code = code | ||
@discovery_display_name = discovery_display_name | ||
@name = name | ||
@primary_service_point_id = primary_service_point_id | ||
@details = details | ||
end | ||
# rubocop:enable Metrics/ParameterLists | ||
|
||
attr_reader :id, :campus_id, :library_id, :institution_id, :code, :discovery_display_name, :name, :primary_service_point_id, :details | ||
|
||
def self.from_hash(dyn) | ||
new( | ||
id: dyn.fetch('id'), | ||
campus: (Campus.new(**dyn.fetch('campus')) if dyn['campus']), | ||
library: (Library.new(**dyn.fetch('library').symbolize_keys) if dyn['library']), | ||
campus_id: dyn.fetch('campusId'), | ||
library_id: dyn['libraryId'] || dyn.dig('library', 'id'), | ||
institution: (Institution.new(id: dyn.fetch('institutionId')) if dyn['institutionId']), | ||
institution_id: dyn.fetch('institutionId'), | ||
code: dyn.fetch('code'), | ||
discovery_display_name: dyn['discoveryDisplayName'] || dyn['name'] || dyn.fetch('id'), | ||
name: dyn['name'], | ||
details: dyn.fetch('details', {}), | ||
primary_service_point_id: dyn['primaryServicePoint'] # present in every location in json, but not from Graphql | ||
) | ||
end | ||
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength | ||
|
||
def library | ||
@library ||= Folio::Types.libraries.find_by(id: library_id) | ||
end | ||
|
||
def campus | ||
@campus ||= Folio::Types.campuses.find_by(id: campus_id) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module Folio | ||
# A cache of campus data | ||
class CampusesStore | ||
def initialize(data_from_cache) | ||
@data = data_from_cache.map { |lib_data| Folio::Campus.from_dynamic(lib_data) } | ||
end | ||
|
||
attr_reader :data | ||
|
||
def find_by(id:) | ||
data.find { |candidate| candidate.id == id } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.