Skip to content

Commit

Permalink
Merge 7f41c38 into 7c80c4a
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Jan 10, 2024
2 parents 7c80c4a + 7f41c38 commit 58daf00
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 8 deletions.
5 changes: 4 additions & 1 deletion app/controllers/names_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def init_related_query_ivars
@has_subtaxa = 0
# Query for names of subtaxa, used in special query link
# Note this is only creating a schematic of a query, used in the link.

# Create query for immediate children.
@children_query = create_query(:Name, :all,
names: @name.id,
Expand Down Expand Up @@ -293,12 +294,14 @@ def init_related_query_ivars
# Don't run if there aren't any children.
@has_subtaxa = @first_child ? @subtaxa_query.select_count : 0
end

# NOTE: `_observation_menu` makes many select_count queries like this!
# That is where most of the heavy loading is. Check helpers/show_name_helper
#
# Third query (maybe combine with second)
@obss = Name::Observations.new(@name)
@best_images = @obss.with_images.take(6).map(&:thumb_image)
# This initiates a query for the images of only the most confident obs
@best_images = @obss.best_images

# This seems like it queries the NameDescription table.
# Would be better to eager load descriptions and derive @best_description
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/footer_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ def html_for_latest_version(obj, versions)
# latest_user = User.safe_find(versions.latest.user_id)
html = html_created_by(obj)

if versions.latest.user_id && obj.updated_at
if versions.last.user_id && obj.updated_at
html << :footer_last_updated_by.t(
user: user_link(versions.latest.user_id),
user: user_link(versions.last.user_id),
date: obj.updated_at.web_time
)
elsif obj.updated_at
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/versions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module VersionsHelper
# Previous Version: N-1<br/>
#
def show_previous_version(obj, versions)
previous_version = versions.latest&.previous
previous_version = versions&.last(2)&.first
if previous_version
previous_version_link(previous_version, obj)
else
Expand Down
6 changes: 6 additions & 0 deletions app/models/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ class Image < AbstractModel
after_update :track_copyright_changes
before_destroy :update_thumbnails

scope :interactive_includes, lambda {
strict_loading.includes(
:image_votes, :license, :projects, :user
)
}

# Array of all observations, users and glossary terms using this image.
def all_subjects
observations + profile_users + glossary_terms
Expand Down
6 changes: 3 additions & 3 deletions app/models/name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -667,14 +667,14 @@ class Name < AbstractModel
}
scope :show_includes, lambda {
strict_loading.includes(
:comments,
# :comments,
:correct_spelling,
{ description: [:authors, :reviewer] },
{ descriptions: [:authors, :editors, :reviewer, :writer_groups] },
{ interests: :user },
:misspellings,
{ namings: [:user] },
{ observations: [:location, :thumb_image, :user] },
# { namings: [:user] },
# { observations: [:location, :thumb_image, :user] },
:rss_log,
{ synonym: :names },
:user,
Expand Down
6 changes: 6 additions & 0 deletions app/models/name/observations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,11 @@ def where_name_proposed
def with_images
of_taxon_this_name.reject { |obs| obs&.thumb_image_id.nil? }
end

def best_images
image_ids = with_images.take(6).map(&:thumb_image_id)
# One new lookup for the images. Order these by image votes
Image.interactive_includes.where(id: image_ids).order(vote_cache: :desc)
end
end
end
4 changes: 3 additions & 1 deletion app/views/controllers/names/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@ add_tab_set(name_show_tabs(name: @name))
</div><!--RIGHT COLUMN-->
</div><!--.row-->

<%= show_object_footer(@name, @versions) %>
<%=
show_object_footer(@name, @versions)
%>

0 comments on commit 58daf00

Please sign in to comment.