Skip to content

Commit

Permalink
Optimized the way we fetch involved people. Added scope to prefetch t…
Browse files Browse the repository at this point in the history
…hem.
  • Loading branch information
damisul committed May 3, 2024
1 parent e58b9be commit 3f6b8e4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ def translated_from_multiple_languages

def incongruous_copyright
@incong = Manifestation.joins(expression: :work)
.with_involved_authorities
.select('expressions.id as expression_id, expressions.intellectual_property')
.select('manifestations.title, manifestations.id as id')
.select(Arel.sql("#{HAS_NON_PUBLIC_DOMAIN_AUTHORITY} as has_non_pd_authority"))
Expand Down
4 changes: 2 additions & 2 deletions app/models/expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class Expression < ApplicationRecord
validates :intellectual_property, presence: true

def editors
return realizers.includes(:person).where(role: Realizer.roles[:editor]).map{|x| x.person}
realizers.to_a.select(&:editor?).map(&:person)
end

def translators
return realizers.includes(:person).where(role: Realizer.roles[:translator]).map {|x| x.person}
realizers.to_a.select(&:translator?).map(&:person)
end

def self.cached_translations_count
Expand Down
1 change: 1 addition & 0 deletions app/models/manifestation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Manifestation < ApplicationRecord
scope :translations, -> { joins(:expression).includes(:expression).where(expressions: {translation: true})}
scope :genre, -> (genre) { joins(expression: :work).where(works: {genre: genre})}
scope :tagged_with, ->(tag_id) {joins(:taggings).where(taggings: {tag_id: tag_id, status: Tagging.statuses[:approved]}).distinct}
scope :with_involved_authorities, -> { preload(expression: { realizers: :person, work: { creations: :person } }) }

SHORT_LENGTH = 1500 # kind of arbitrary...
LONG_LENGTH = 15000 # kind of arbitrary...
Expand Down
4 changes: 2 additions & 2 deletions app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class Work < ApplicationRecord
# has_and_belongs_to_many :people # superseded by creations and persons above

def authors
return creations.author.includes(:person).map(&:person)
return creations.to_a.select(&:author?).map(&:person)
end

def illustrators
return creations.illustrator.includes(:person).map(&:person)
return creations.to_a.select(&:illustrator?).map(&:person)
end

def first_author
Expand Down

0 comments on commit 3f6b8e4

Please sign in to comment.