myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [1972] branches/event_logging/app: Subscriptions.


From: noreply
Subject: [myexperiment-hackers] [1972] branches/event_logging/app: Subscriptions.
Date: Mon, 17 Nov 2008 06:54:39 -0500 (EST)

Revision
1972
Author
alekses6
Date
2008-11-17 06:54:39 -0500 (Mon, 17 Nov 2008)

Log Message

Subscriptions. Populated contents of "My Activity" tab on user profile page. This is only shown to the user themself and contains only actions initiated by them.

Modified Paths

Diff

Modified: branches/event_logging/app/helpers/application_helper.rb (1971 => 1972)


--- branches/event_logging/app/helpers/application_helper.rb	2008-11-14 18:12:00 UTC (rev 1971)
+++ branches/event_logging/app/helpers/application_helper.rb	2008-11-17 11:54:39 UTC (rev 1972)
@@ -596,7 +596,9 @@
   #            (NIL to process all events within ["after".."before"] timeframe)
   # 6) current_viewer - User instance, which requests to generate the news 
   #                     (zero or NIL value indicates not logged in viewer; also a setting for RSS feeds, etc - only public events will be shown)
-  def news(news_for, restrict_contributor=true, before=Time.now, after=Time.now-DEFAULT_NEWS_TIMEFRAME, limit=DEFAULT_NEWS_COUNT, current_viewer=nil)
+  # 7) contributor_initiated_actions_only - (active only when "restrict_contributor" set to 'true'); 'true' to process only the actions in the
+  #                                         event log, when "news_for" is a 'contributor' and where it is the "culprit" of the action
+  def news(news_for, restrict_contributor=true, before=Time.now, after=Time.now-DEFAULT_NEWS_TIMEFRAME, limit=DEFAULT_NEWS_COUNT, current_viewer=nil, contributor_initiated_actions_only=false)
     hash = {}
     
     # if event logging is switched off in "environment_private.rb" - no news can be generated
@@ -610,7 +612,7 @@
     if news_for.nil?
       news_array = news_from_log_public(before, after, limit, current_viewer)
     elsif ["User", "Network"].include? (news_for.class.to_s)
-      news_array = news_from_log_for_contributor(news_for, before, after, restrict_contributor, false, limit, current_viewer)
+      news_array = news_from_log_for_contributor(news_for, before, after, restrict_contributor, contributor_initiated_actions_only, false, limit, current_viewer)
     elsif ["Workflow", "Blob", "Pack"].include? (news_for.class.to_s)
       news_array = news_from_log_for_contributable(news_for, before, after, limit, current_viewer)
     end
@@ -1412,13 +1414,15 @@
   # 3) after - Time object, indicating the time after which the events to be displayed (like a week ago and onwards)
   # 4) contributor_news_only - set to "true" to get events relevant for the current user only (used on user/group profile pages);
   #                                OR "false" to get events for friends and group members where contributor is a member of, too (used for "my news" page);
-  # 5) return_raw_events - used for recursive calls; when set to "true" a set of events from ActivityLog table is returned;
+  # 5) contributor_initiated_actions_only - (active only when "contributor_news_only" set to 'true'); 'true' to process only the actions in the
+  #                                         event log, where "contributor" is the "culprit" of the action
+  # 6) return_raw_events - used for recursive calls; when set to "true" a set of events from ActivityLog table is returned;
   #                        "false" will cause the events to be interpreted and returned as news item;
-  # 6) limit - the number of news entries to produce (the lower the value, the more positive effect on performance this has)
+  # 7) limit - the number of news entries to produce (the lower the value, the more positive effect on performance this has)
   #            (NIL will yield news entries interpreting ALL events in ["after".."before"] timeframe)
-  # 7) current_viewer - User instance, who is currently requests news to be generated
+  # 8) current_viewer - User instance, who is currently requests news to be generated
   #                     (zero or NIL for anonymous user - that is for public news feed: like for RSS feeds, etc)
-  def news_from_log_for_contributor(contributor, before, after, contributor_news_only, return_raw_events, limit, current_viewer)
+  def news_from_log_for_contributor(contributor, before, after, contributor_news_only, contributor_initiated_actions_only, return_raw_events, limit, current_viewer)
     
     # DEBUG
     # puts "=================================="
@@ -1501,7 +1505,12 @@
     # get events for current contributor
     # (no need to impose order on the DB query, as more queries will be run [for "related_contributors"]
     #  and subsequent sorting will be required anyway)
-    events = ActivityLog.find(:all, :conditions => ["created_at > ? AND created_at < ? AND ((activity_loggable_type = ? AND activity_loggable_id = ?) OR (culprit_type = ? AND culprit_id = ?) OR (referenced_type = ? AND referenced_id = ?))", after, before, contributor.class.to_s, contributor.id, contributor.class.to_s, contributor.id, contributor.class.to_s, contributor.id])
+    unless contributor_news_only && contributor_initiated_actions_only
+      events = ActivityLog.find(:all, :conditions => ["created_at > ? AND created_at < ? AND ((activity_loggable_type = ? AND activity_loggable_id = ?) OR (culprit_type = ? AND culprit_id = ?) OR (referenced_type = ? AND referenced_id = ?))", after, before, contributor.class.to_s, contributor.id, contributor.class.to_s, contributor.id, contributor.class.to_s, contributor.id])
+    else
+      # only fetch events where "contributor" is the 'culprit' of the action
+      events = ActivityLog.find(:all, :conditions => ["created_at > ? AND created_at < ? AND (culprit_type = ? AND culprit_id = ?)", after, before, contributor.class.to_s, contributor.id])
+    end
     events.concat(events_as_admin)
     
     # if any "related_contributors", get events for each
@@ -1509,7 +1518,7 @@
     #  than some of the contributor in the original query)
     events_for_related_contributor = []
     related_contributors.each do |c|
-      events_for_related_contributor = news_from_log_for_contributor(c, before, after, true, true, limit, current_viewer) 
+      events_for_related_contributor = news_from_log_for_contributor(c, before, after, true, false, true, limit, current_viewer) 
       events.concat(events_for_related_contributor) 
     end
     return events if return_raw_events
@@ -1525,8 +1534,8 @@
     # of events - this should include events related to contributables
     # belonging to the user, favourited by the user, etc 
     
-    # NB! only show this on the user's "home" page / profile page (never for the groups)
-    if contributor.class.to_s == "User"
+    # NB! only show this on the user's "home" page / profile page (never for the groups or "My Activity" feed on user profile page)
+    if contributor.class.to_s == "User" && !contributor_initiated_actions_only
       # ==== Announcements ====
       # add site announcements to the event list; (this user with no friends who are site admins AND
       # who is not a member of any groups, where site admins are members too, will still get news

Modified: branches/event_logging/app/views/networks/news.rxml (1971 => 1972)


--- branches/event_logging/app/views/networks/news.rxml	2008-11-14 18:12:00 UTC (rev 1971)
+++ branches/event_logging/app/views/networks/news.rxml	2008-11-17 11:54:39 UTC (rev 1972)
@@ -6,6 +6,6 @@
     xml.ttl "60"
     xml.tag! "atom:link", :rel => 'search', :type => 'application/opensearchdescription+xml', :href ="" "http://#{request.host_with_port}/open_search.xml"
     xml.description "RSS feed listing the public group news for address@hidden Group on myExperiment.org"
-    render(:partial => "layouts/news_entry", :collection => news_from_log_for_contributor(@network, Time.now, Time.now-DEFAULT_PUBLIC_NEWS_RSS_TIMEFRAME, true, false, DEFAULT_PUBLIC_NEWS_RSS_COUNT, nil), :locals => { :xm => xml, :group => @network })
+    render(:partial => "layouts/news_entry", :collection => news_from_log_for_contributor(@network, Time.now, Time.now-DEFAULT_PUBLIC_NEWS_RSS_TIMEFRAME, true, false, false, DEFAULT_PUBLIC_NEWS_RSS_COUNT, nil), :locals => { :xm => xml, :group => @network })
   end
 end
\ No newline at end of file

Modified: branches/event_logging/app/views/users/show.rhtml (1971 => 1972)


--- branches/event_logging/app/views/users/show.rhtml	2008-11-14 18:12:00 UTC (rev 1971)
+++ branches/event_logging/app/views/users/show.rhtml	2008-11-17 11:54:39 UTC (rev 1972)
@@ -361,11 +361,14 @@
     <% end %>
 	
 	<% when "My Activity" %>
+	  <% benchmark "User profile 'My Activity' news feed" do %>
+      <% viewer_id = (logged_in? ? current_user.id : "public") -%>
+			<% # this is only visible to the owner of the profile, so only a single viewer ever exists -%>
+			<% cache_timeout({ :controller => 'news', :action ="" 'user_activity', :id => @user.id } , NEWS_CACHE_TIMEOUT.seconds.from_now ) do -%>
+  			<%= render :partial => "layouts/news", :locals => { :collection => news(@user, true, Time.now, Time.now-DEFAULT_USER_NEWS_TIMEFRAME, DEFAULT_USER_NEWS_COUNT, current_user, true) } %>
+		  <% end %>
+    <% end %>
 	
-	  <div>
-
-	  </div>
-	
   <% when "Friends" %>
 
     <div>

reply via email to

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