From 4c24d5cd50cd54b3a2b04f6b2ef0c999c8ff404a Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Wed, 3 May 2023 22:53:04 +0200 Subject: [PATCH] optimize and remove the unused methods in the home index action --- app/controllers/home_controller.rb | 69 ++++++++---------------------- app/views/home/index.html.haml | 8 ++-- 2 files changed, 23 insertions(+), 54 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 388410dba..0dec1e2ea 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -7,68 +7,37 @@ class HomeController < ApplicationController include FairScoreHelper def index - @ontologies_views = LinkedData::Client::Models::Ontology.all(include_views: true) - @ontologies = @ontologies_views.select {|o| !o.viewOf} - @ontologies_hash = Hash[@ontologies_views.map {|o| [o.acronym, o]}] - @groups = LinkedData::Client::Models::Group.all - @notes = LinkedData::Client::Models::Note.all - @last_notes = [] - unless @notes.empty? - @notes.sort! {|a,b| b.created <=> a.created } - @notes[0..20].each do |n| - ont_uri = n.relatedOntology.first - ont = LinkedData::Client::Models::Ontology.find(ont_uri) - next if ont.nil? - username = n.creator.split("/").last - note = { - :uri => n.links['ui'], - :id => n.id, - :subject => n.subject, - :body => n.body, - :created => n.created, - :author => username, - :ont_name => ont.name - } - @last_notes.push note - break if @last_notes.length >= [$HOME_LATEST_NOTES_COUNT.to_i, 5].max - end - end - # Get the latest manual mappings - # All mapping classes are bidirectional. - # Each class in the list maps to all other classes in the list. - if $DISPLAY_RECENT.nil? || $DISPLAY_RECENT == true - @recent_mappings = get_recent_mappings # application_controller - end - - organize_groups + @analytics = LinkedData::Client::Analytics.last_month # Calculate BioPortal summary statistics - @ont_count = @ontologies.length - @cls_count = LinkedData::Client::Models::Metrics.all.map { |m| m.classes.to_i }.sum - @individuals_count = LinkedData::Client::Models::Metrics.all.map {|m| m.individuals.to_i}.sum - @prop_count = 36286 + @ont_count = @analytics.onts.size + metrics = LinkedData::Client::Models::Metrics.all + metrics = metrics.each_with_object(Hash.new(0)) do |h, sum| + h.to_hash.slice(:classes, :properties, :individuals).each { |k, v| sum[k] += v } + end + + @cls_count = metrics[:classes] + @individuals_count = metrics[:individuals] + @prop_count = metrics[:properties] @map_count = total_mapping_count - @analytics = LinkedData::Client::Analytics.last_month @projects_count = LinkedData::Client::Models::Project.all.length @users_count = LinkedData::Client::Models::User.all.length - @ontology_names = @ontologies.map { |ont| ["#{ont.name} (#{ont.acronym})", ont.acronym] } - @upload_benifits = [ - "Discover new insights and connections by exploring other ontologies in the repository.", - "Contribute to the growth and development of your domain by adding new concepts and categories.", - "Use version control to manage the changes to your ontology over time and collaborate with other users.", - "Get feedback and suggestions from other users who can review and comment on your ontology.", - "Get the FAIR score and metrics for your ontology." + + @upload_benefits = [ + 'Discover new insights and connections by exploring other ontologies in the repository.', + 'Contribute to the growth and development of your domain by adding new concepts and categories.', + 'Use version control to manage the changes to your ontology over time and collaborate with other users.', + 'Get feedback and suggestions from other users who can review and comment on your ontology.', + 'Get the FAIR score and metrics for your ontology.' ] - @anal_ont_names = {} + @anal_ont_names = [] @anal_ont_numbers = [] @analytics.onts[0..4].each do |visits| - ont = @ontologies_hash[visits[:ont].to_s] - @anal_ont_names[ont.acronym] = ont.name + @anal_ont_names << visits[:ont] @anal_ont_numbers << visits[:views] end - end def render_layout_partial diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index e4977b3a4..6f4692c07 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -21,17 +21,17 @@ %img{:src => asset_path("home-random-bubbles.svg")}/ .home-bubble.home-bubble-one %h5 - = @anal_ont_names.keys[0] + = @anal_ont_names[0] %p = @anal_ont_numbers[0].to_s + " visits" .home-bubble.home-bubble-two %h5 - = @anal_ont_names.keys[1] + = @anal_ont_names[1] %p = @anal_ont_numbers[1].to_s + " visits" .home-bubble.home-bubble-three %h5 - = @anal_ont_names.keys[2] + = @anal_ont_names[2] %p = @anal_ont_numbers[2].to_s + " visits" %a.home-bubble.home-bubble-four{:href => "/visits"} @@ -49,7 +49,7 @@ %p Uploading an ontology is a way of sharing your domain knowledge with others. %p By uploading your ontology to agroportal, you can: .home-upload-benifits - - @upload_benifits.each do |benifit| + - @upload_benefits.each do |benifit| %div %img{:src => asset_path("check-outlined.svg")}/ %p