Skip to content

Commit

Permalink
Removing old inefficient set_sidebar #8803 (#8928)
Browse files Browse the repository at this point in the history
* Removing set_sidebar

* Removing old set_sidebar
  • Loading branch information
gauravahlawat81 authored Jan 14, 2021
1 parent 2a52bfd commit a3c8796
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 52 deletions.
44 changes: 0 additions & 44 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,6 @@ def set_raven_context
Raven.extra_context(params: params.to_unsafe_h, url: request.url)
end

# eventually videos could be a power tag
def set_sidebar(type = :generic, data = :all, args = {})
args[:note_count] ||= 8
if type == :tags # accepts data of array of tag names as strings
@notes ||= if params[:controller] == 'questions'
Tag.find_nodes_by_type(data, 'note', args[:note_count])
else
Tag.find_research_notes(data, args[:note_count])
end

@notes = @notes.where('node.nid != (?)', @node.nid) if @node
@wikis = Tag.find_pages(data, 10)
@videos = Tag.find_nodes_by_type_with_all_tags(%w(video) + data, 'note', 8) if args[:videos] && data.length > 1
@maps = Tag.find_nodes_by_type(data, 'map', 20)
else # type is generic
# remove "classroom" postings; also switch to an EXCEPT operator in sql, see https://github.com/publiclab/plots2/issues/375
hidden_nids = Node.hidden_response_node_ids
@notes = if params[:controller] == 'questions'
Node.questions
.joins(:revision)
else
Node.research_notes.joins(:revision).order('node.nid DESC').paginate(page: params[:page])
end

@notes = @notes.where('node.nid != (?)', @node.nid) if @node
@notes = @notes.where('node_revisions.status = 1 AND node.nid NOT IN (?)', hidden_nids) unless hidden_nids.empty?

@notes = if logged_in_as(['admin', 'moderator'])
@notes.where('(node.status = 1 OR node.status = 4)')
elsif current_user
@notes.where('(node.status = 1 OR (node.status = 4 AND node.uid = ?))', current_user.uid)
else
@notes.where('node.status = 1')
end

@wikis = Node.order('changed DESC')
.joins(:revision)
.where('node_revisions.status = 1 AND node.status = 1 AND type = "page"')
.limit(10)
.group('node_revisions.nid')
.order('node_revisions.timestamp DESC')
end
end

# non-Authlogic... homebrew
def prompt_login(message = I18n.t('application_controller.must_be_logged_in'))
flash[:warning] = message
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/map_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def show
@tags = @node.tags
@tagnames = @tags.collect(&:name)

set_sidebar :tags, @tagnames
# set_sidebar :tags, @tagnames
end

def edit
Expand Down Expand Up @@ -234,7 +234,7 @@ def create
end

def tag
set_sidebar :tags, [params[:id]], note_count: 20
# set_sidebar :tags, [params[:id]], note_count: 20

@tagnames = params[:id].split(',')
nids = Tag.find_nodes_by_type(params[:id], 'map', 20).collect(&:nid)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def show
@tags = @node.tags
@tagnames = @tags.collect(&:name)
@preview = false
set_sidebar :tags, @tagnames
# set_sidebar :tags, @tagnames
else
page_not_found
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def filter_questions_by_tag(questions, tagnames)

def index
@title = 'Questions and Answers'
set_sidebar
# set_sidebar
@pagy, @questions = pagy(Node.questions
.where(status: 1)
.order('node.nid DESC'), items: 24)
Expand Down Expand Up @@ -86,7 +86,7 @@ def show
.order(Arel.sql('count(*) DESC'))
.collect(&:author)

set_sidebar :tags, @tagnames
# set_sidebar :tags, @tagnames
end

def recently_commented
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def rss_for_tagged_with_author
end

def contributors
set_sidebar :tags, [params[:id]], note_count: 20
# set_sidebar :tags, [params[:id]], note_count: 20
@tagnames = [params[:id]]
@tag = Tag.find_by(name: params[:id])
@note_count = Tag.tagged_node_count(params[:id]) || 0
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/wiki_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def show
redirect_to '/wiki'
end
@tagnames = @tags.collect(&:name)
set_sidebar :tags, @tagnames, videos: true
# set_sidebar :tags, @tagnames, videos: true
@wikis = Tag.find_pages(@node.slug_from_path, 30) if @node.has_tag('chapter') || @node.has_tag('tabbed:wikis')

impressionist(@node, 'show', unique: [:ip_address])
Expand Down Expand Up @@ -295,7 +295,7 @@ def revision
@tagnames = @tags.collect(&:name)
@unpaginated = true
@is_revision = true
set_sidebar :tags, @tagnames, videos: true
# set_sidebar :tags, @tagnames, videos: true
@revision = Revision.find_by_nid_and_vid(@node.id, params[:vid])
if @revision.nil?
flash[:error] = I18n.t('wiki_controller.revision_not_found')
Expand Down

0 comments on commit a3c8796

Please sign in to comment.