Permalink
Browse files

Simplifying bookmarks controller for performance reasons as we work o…

…n overhauling it
  • Loading branch information...
1 parent 1bac70e commit 58470b403a17a48ccd8cb601ec213fdbef649f49 @elzj elzj committed Jun 4, 2012
Showing with 13 additions and 38 deletions.
  1. +13 −38 app/controllers/bookmarks_controller.rb
@@ -89,10 +89,6 @@ def index
@bookmarks= owner.bookmarks
end
- if params[:recs_only]
- @bookmarks = @bookmarks.recs
- end
-
if @user && @user == current_user
# can see all own bookmarks
elsif logged_in_as_admin?
@@ -103,52 +99,31 @@ def index
@bookmarks = @bookmarks.visible_to_all
end
else
- # Aggregate on main bookmarks page and tags bookmarks page
+ flash[:notice] = ts("Bookmark pages are currently being reworked. Apologies for the inconvenience!")
if params[:tag_id] # tag page
unless owner
raise ActiveRecord::RecordNotFound, "Couldn't find tag named '#{params[:tag_id]}'"
- end
- bookmarks_on_synonyms = []
- if params[:recs_only]
- bookmarks_primary = owner.bookmarks.recs
- owner.synonyms.each do |synonym|
- bookmarks_on_synonyms << synonym.bookmarks.recs
- bookmarks_on_synonyms << synonym.indirect_bookmarks(true)
- end rescue NoMethodError
- bookmarks_indirect = owner.indirect_bookmarks(true)
- else
- bookmarks_primary = owner.bookmarks
- owner.synonyms.each do |synonym|
- bookmarks_on_synonyms << synonym.bookmarks
- bookmarks_on_synonyms << synonym.indirect_bookmarks
- end rescue NoMethodError
- bookmarks_indirect = owner.indirect_bookmarks
end
- all_bookmarks = (bookmarks_primary + bookmarks_on_synonyms + bookmarks_indirect).flatten.compact
- bookmarks_grouped = all_bookmarks.reject{|b| !b.visible?(current_user) || (b.bookmarkable && !b.bookmarkable.visible?(current_user))}.group_by(&:bookmarkable)
+ @bookmarks = owner.bookmarks
else # main page
@most_recent_bookmarks = true
+ @bookmarks = Bookmark.recent.visible_to_user(current_user)
if params[:recs_only]
- bookmarks_grouped = Bookmark.recs.recent.visible_to_user(current_user).group_by(&:bookmarkable)
@page_subtitle = ts("recs")
- else
- bookmarks_grouped = Bookmark.recent.visible_to_user(current_user).group_by(&:bookmarkable)
end
end
- @bookmarks = []
- bookmarks_grouped.values.each do |bookmarks|
- if bookmarks.size == 1 || bookmarks.map(&:bookmarkable_type).uniq.size == 1
- @bookmarks << bookmarks.first
- else
- bookmarkables = bookmarks.map(&:bookmarkable).uniq.compact
- bookmarkables.each do |bookmarkable|
- @bookmarks << bookmarkable.bookmarks.is_public.first
- end
- end
+ if logged_in_as_admin?
+ @bookmarks = @bookmarks.visible_to_admin
+ elsif logged_in?
+ @bookmarks = @bookmarks.visible_to_registered_user
+ else
+ @bookmarks = @bookmarks.visible_to_all
end
- @bookmarks = @bookmarks.sort_by{|b| - b.id}
end
- @bookmarks = @bookmarks.compact.paginate(:page => params[:page])
+ if params[:recs_only]
+ @bookmarks = @bookmarks.recs
+ end
+ @bookmarks = @bookmarks.paginate(:page => params[:page])
end
# GET /:locale/bookmark/:id

0 comments on commit 58470b4

Please sign in to comment.