myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [1925] branches/event_logging: News generation.


From: noreply
Subject: [myexperiment-hackers] [1925] branches/event_logging: News generation.
Date: Thu, 6 Nov 2008 06:43:15 -0500 (EST)

Revision
1925
Author
alekses6
Date
2008-11-06 06:43:15 -0500 (Thu, 06 Nov 2008)

Log Message

News generation. Old method of news generation is completely removed from the DB.

Modified Paths

Diff

Modified: branches/event_logging/app/helpers/application_helper.rb (1924 => 1925)


--- branches/event_logging/app/helpers/application_helper.rb	2008-11-05 16:23:52 UTC (rev 1924)
+++ branches/event_logging/app/helpers/application_helper.rb	2008-11-06 11:43:15 UTC (rev 1925)
@@ -594,15 +594,12 @@
   def news(contributor, restrict_contributor=true, before=Time.now, after=Time.now-DEFAULT_NEWS_TIMEFRAME, limit=DEFAULT_NEWS_COUNT, current_viewer=nil)
     hash = {}
     
-    # choose news generation method: 
-    # - new (faster / more news types), but requires ActivityLogs to be enabled
-    # - old (slow), but collects news items from all across the DB
-    if USE_EVENT_LOG && GENERATE_NEWS_FROM_EVENT_LOG
-      news_array = contributor_news_from_log(contributor, before, after, restrict_contributor, false, limit, current_viewer)
-    else
-      news_array = contributor_news(contributor, before, after, 0, (restrict_contributor ? contributor : nil))
-    end
+    # if event logging is switched off in "environment_private.rb" - no news can be generated
+    return hash unless USE_EVENT_LOG
     
+    # collect all activity log events and interpret them as news entries
+    news_array = contributor_news_from_log(contributor, before, after, restrict_contributor, false, limit, current_viewer)
+    
     news_array.sort! { |a, b|
       b[0] <=> a[0]
     }[0..limit].each do |news_item|
@@ -2194,173 +2191,6 @@
   end
   
   ######################################################  
-  
-  def contributor_news(contributor, before, after, depth, restrict_contributor)
-    rtn = []
-    
-    return rtn unless depth.to_i < 2
-    
-    collections = [[contributor], contributor.contributions, contributor.workflows, contributor.blogs]
-    recursions = []
-    
-    case contributor.class.to_s
-    when "User"
-      collections = collections + [contributor.memberships_accepted, contributor.friendships_accepted, contributor.networks_owned, contributor.picture_selections]
-      recursions = recursions + [contributor.networks, contributor.networks_owned, contributor.friends]
-    when "Network"
-      collections = collections + [contributor.memberships_accepted]
-      recursions = recursions + [contributor.members]
-    else
-      # do nothing!
-    end
-    
-    collections.each do |collection|
-      collection.each do |item|
-        rtn = rtn + contributor_news!(item, before, after, restrict_contributor)
-      end
-    end
-    
-    recursions.each do |collection|
-      collection.each do |c|
-        rtn = rtn + contributor_news(c, before, after, depth.to_i+1, restrict_contributor)
-      end
-    end
-    
-    return rtn.uniq # remove duplicate items due to recursion
-  end
-  
-  def contributor_news!(item, before, after, restrict_contributor)
-    rtn = []
-    
-    case (item.class.to_s)
-    when "Membership"
-      return rtn if before and item.accepted_at > before
-      return rtn if after and item.accepted_at < after
-        
-      if restrict_contributor
-        case restrict_contributor.class.to_s
-        when "User"
-          return rtn unless item.user.id.to_i == restrict_contributor.id.to_i
-        when "Network"
-          return rtn unless item.network.id.to_i == restrict_contributor.id.to_i
-        else
-          return rtn
-        end
-      end
-      
-      rtn << [item.accepted_at, "#{name(item.user)} joined the #{title(item.network)} Group."]
-    when "Friendship"
-      return rtn if before and item.accepted_at > before
-      return rtn if after and item.accepted_at < after
-        
-      if restrict_contributor 
-        return rtn unless (restrict_contributor.class.to_s == "User" and [item.user.id.to_i, item.friend.id.to_i].include? restrict_contributor.id.to_i)
-      end
-      
-      rtn << [item.accepted_at, "#{name(item.user)} and #{name(item.friend)} became friends."]
-    when "Network"
-      return rtn if before and item.created_at > before
-      return rtn if after and item.created_at < after
-        
-      if restrict_contributor
-        case restrict_contributor.class.to_s
-        when "User"
-          return rtn unless item.owner.id.to_i == restrict_contributor.id.to_i
-        when "Network"
-          return rtn unless item.id.to_i == restrict_contributor.id.to_i
-        else
-          return rtn
-        end
-      end
-      
-      rtn << [item.created_at, "#{name(item.owner)} created the #{title(item)} Group."]
-    when "User"
-      return rtn if before and item.created_at > before
-      return rtn if after and item.created_at < after
-        
-      if restrict_contributor
-        return rtn unless (restrict_contributor.class.to_s == "User" and item.id.to_i == restrict_contributor.id.to_i)
-      end
-      
-      rtn << [item.created_at, "#{name(item)} joined #{link_to "myExperiment", "/"}."]
-    when "Contribution"
-      return rtn if before and item.created_at > before
-      return rtn if after and item.created_at < after
-        
-      owner = contributor(item.contributor_id, item.contributor_type)
-      editor = contributor(item.contributable.contributor_id, item.contributable.contributor_type)
-        
-      if restrict_contributor 
-        return rtn unless ([item.contributable.contributor_type, item.contributor_type].include? restrict_contributor.class.to_s and [item.contributable.contributor_id, item.contributor_id].include? restrict_contributor.id.to_i)
-      end
-      
-      case item.contributable_type.to_s
-      when "Workflow"
-        if item.contributable.current_version.to_i == 1
-          title = item.contributable.title
-        else
-          title = item.contributable.versions[0].title
-        end
-          
-        link = link_to h(title), url_for(:controller => :workflows, :action ="" :show, :id => item.contributable_id, :version => 1)
-      else
-        link = contributable(item.contributable_id, item.contributable_type)
-      end
-        
-      if owner.to_s == editor.to_s
-        rtn << [item.created_at, "#{owner} created the #{link} #{item.contributable_type.downcase == "blob" ? "File" : item.contributable_type.downcase}."]
-      else
-        case item.contributor_type
-        when "Network"
-          owner_string = "the #{owner} network"
-        else
-          owner_string = owner
-        end
-        
-        rtn << [item.created_at, "#{editor} created the #{link} #{item.contributable_type.downcase == "blob" ? "File" : item.contributable_type.downcase} for #{owner_string}."]
-      end
-    when "Blog"
-      if restrict_contributor
-        return rtn unless (restrict_contributor.class.to_s == item.contributor_type.to_s and restrict_contributor.id.to_i == item.contributor_id.to_i)
-      end
-      
-      owner = contributor(item.contributor_id, item.contributor_type)
-    
-      item.posts.each do |blog_post|
-        next if before and blog_post.created_at > before
-        next if after and blog_post.created_at < after
-        
-        rtn << [blog_post.created_at, "#{owner} has created a new post on #{contributable(item.id, "Blog")}."]
-      end
-    when "Workflow"
-      item.versions.each do |workflow|
-        next if workflow.version.to_i == 1
-        next if before and workflow.updated_at > before
-        next if after and workflow.updated_at < after
-        
-        editor = contributor(workflow.contributor_id, workflow.contributor_type)
-        
-        if restrict_contributor
-          next unless (workflow.contributor_type.to_s == restrict_contributor.class.to_s and workflow.contributor_id.to_i == restrict_contributor.id.to_i)
-        end
-        
-        rtn << [workflow.updated_at, "#{editor} edited the #{versioned_workflow_link(item.id, workflow.version, false)} Workflow."]
-      end
-    when "PictureSelection"
-      return rtn if before and item.created_at > before
-      return rtn if after and item.created_at < after
-        
-      if restrict_contributor
-        return rtn unless (restrict_contributor.class.to_s == "User" and item.user_id.to_i == restrict_contributor.id.to_i)
-      end
-      
-      rtn << [item.created_at, "#{name(item.user)} selected a new avatar #{link_to image_tag(avatar_url(item.picture_id, 50)), user_path(item.user)}."]
-    else
-      return rtn
-    end
-    
-    return rtn
-  end
 
   def permissions_categorised(permissions)
     permissions_categorised={'announcement'=>[],'citation'=>[],'comment'=>[],'download'=>[],'experiment'=>[],'file'=>[],'group'=>[],'job'=>[],'message'=>[],'pack'=>[],'picture'=>[],'review'=>[],'runner'=>[],'tag'=>[],'user'=>[],'workflow'=>[],'miscellaneous'=>[]};

Modified: branches/event_logging/config/environment_private.rb.pre (1924 => 1925)


--- branches/event_logging/config/environment_private.rb.pre	2008-11-05 16:23:52 UTC (rev 1924)
+++ branches/event_logging/config/environment_private.rb.pre	2008-11-06 11:43:15 UTC (rev 1925)
@@ -79,12 +79,6 @@
 # Switch event logging on or off
 USE_EVENT_LOG = true
 
-# Choose a method of news generation:
-# "true" to generate news from event log;
-# "false" to use older (slower) system that queries multiple DB tables;
-# (this will only be considered if "USE_EVENT_LOG == true")
-GENERATE_NEWS_FROM_EVENT_LOG = true
-
 # Default timeframes for various types of news
 # [this means that only events after (Time.now - DEFAULT_<>_TIMEFRAME) will be fetched from event log]
 DEFAULT_NEWS_TIMEFRAME = 1.week

reply via email to

[Prev in Thread] Current Thread [Next in Thread]