app/models/taxon_concept.rb
# TODO: this belongs in, at worst, TaxonPage... at best, TaxonOverview
# (though TaxonDetails needs access to the other method). ...But the API is
# using this and I don't want to touch the API quite yet. TODO: stop passing
# in a user, just a language. See #best_article_for_user and you'll see it
# essentially ignores the user entirely anyway (with reason).
this belongs in, at worst, TaxonPage... at best, TaxonOverview
(though TaxonDetails needs access to the other method). ...But the API is
using this and I don't want to touch the API quite yet. TODO: stop passing
in a user, just a language. See #best_article_for_user and you'll see it
essentially ignores the user entirely anyway (with reason).
this belongs in at worst TaxonPage ... at best TaxonOverview ( though TaxonDetails needs access to the other method ) . ... But the API is using this and I don ' t want to touch the API quite yet . TODO : stop passing in a user just a language . See #best_article_for_user and you ' ll see it essentially ignores the user entirely anyway ( with reason ) .
def overview_text_for_user(the_user)
    @overview_text_for_user ||= {}
    return @overview_text_for_user[the_user.id] if the_user && @overview_text_for_user[the_user.id]
    the_user ||= EOL::AnonymousUser.new(Language.default)
    TaxonConcept.prepare_cache_classes
    cached_key = TaxonConcept.cached_name_for("best_article_id_#{id}_#{the_user.language_id}")
    best_article_id ||= Rails.cache.read(cached_key)
    return nil if best_article_id == 0 
    if best_article_id && DataObject.still_published?(best_article_id)
      article = DataObject.find(best_article_id)
      @overview_text_for_user[the_user.id] = article
      return article
    else
      article = best_article_for_user(the_user)
      expire_time = article.nil? ? 1.day : 1.week
      Rails.cache.fetch(cached_key, expires_in: expire_time) { article.nil? ? 0 : article.id }
      @overview_text_for_user[the_user.id] = article
      return article
    end
  end
def overview_text_for_user ( the_user ) @overview_text_for_user ||= { } return @overview_text_for_user [ the_user . id ] if the_user && @overview_text_for_user [ the_user . id ] the_user ||= EOL :: AnonymousUser . new ( Language . default ) TaxonConcept . prepare_cache_classes cached_key = TaxonConcept . cached_name_for ( "best_article_id_#{id}_#{the_user.language_id}" ) best_article_id ||= Rails . cache . read ( cached_key ) return nil if best_article_id == 0 if best_article_id && DataObject . still_published? ( best_article_id ) article = DataObject . find ( best_article_id ) @overview_text_for_user [ the_user . id ] = article return article else article = best_article_for_user ( the_user ) expire_time = article . nil? ? 1 . day : 1 . week Rails . cache . fetch ( cached_key , expires_in : expire_time ) { article . nil? ? 0 : article . id } @overview_text_for_user [ the_user . id ] = article return article end end
TODO: this belongs in, at worst, TaxonPage... at best, TaxonOverview
(though TaxonDetails needs access to the other method).
TODO : this belongs in at worst TaxonPage ... at best TaxonOverview ( though TaxonDetails needs access to the other method ) .
# Nothing's available, quickly move on...
the_user
<not_specific>