Shorten some very long lines

Prevent warnings from already defined constants when reloading
This commit is contained in:
Régis Hanol 2017-08-12 04:18:04 +02:00
parent c2061aae3d
commit 75e4f7f896
5 changed files with 23 additions and 32 deletions

View File

@ -1,7 +1,7 @@
class PostSerializer < BasicPostSerializer class PostSerializer < BasicPostSerializer
# To pass in additional information we might need # To pass in additional information we might need
INSTANCE_VARS = [ INSTANCE_VARS ||= [
:topic_view, :topic_view,
:parent_post, :parent_post,
:add_raw, :add_raw,
@ -310,9 +310,7 @@ class PostSerializer < BasicPostSerializer
end end
def include_user_custom_fields? def include_user_custom_fields?
return if @topic_view.blank? (@topic_view&.user_custom_fields || {})[object.user_id]
custom_fields = @topic_view.user_custom_fields
custom_fields && custom_fields[object.user_id]
end end
def static_doc def static_doc
@ -354,17 +352,16 @@ class PostSerializer < BasicPostSerializer
private private
def post_actions def post_actions
@post_actions ||= (@topic_view.present? && @topic_view.all_post_actions.present?) ? @topic_view.all_post_actions[object.id] : nil @post_actions ||= (@topic_view&.all_post_actions || {})[object.id]
end end
def active_flags def active_flags
@active_flags ||= (@topic_view.present? && @topic_view.all_active_flags.present?) ? @topic_view.all_active_flags[object.id] : nil @active_flags ||= (@topic_view&.all_active_flags || {})[object.id]
end end
def post_custom_fields def post_custom_fields
@post_custom_fields ||= @post_custom_fields ||= if @topic_view
if @topic_view (@topic_view.post_custom_fields || {})[object.id] || {}
(@topic_view.post_custom_fields && @topic_view.post_custom_fields[object.id]) || {}
else else
object.custom_fields object.custom_fields
end end

View File

@ -20,19 +20,17 @@ module PostStreamSerializerMixin
end end
def posts def posts
return @posts if @posts.present? @posts ||= begin
@posts = [] (object.posts || []).map do |post|
if object.posts post.topic = object.topic
object.posts.each do |p|
ps = PostSerializer.new(p, scope: scope, root: false)
ps.add_raw = true if @options[:include_raw]
ps.topic_view = object
p.topic = object.topic
@posts << ps.as_json serializer = PostSerializer.new(post, scope: scope, root: false)
serializer.add_raw = true if @options[:include_raw]
serializer.topic_view = object
serializer.as_json
end end
end end
@posts
end end
end end

View File

@ -255,9 +255,7 @@ class TopicViewSerializer < ApplicationSerializer
end end
def topic_timer def topic_timer
TopicTimerSerializer.new( TopicTimerSerializer.new(object.topic.public_topic_timer, root: false)
object.topic.public_topic_timer, root: false
)
end end
def tags def tags

View File

@ -3,7 +3,7 @@ module Plugin; end
class Plugin::Metadata class Plugin::Metadata
OFFICIAL_PLUGINS = Set.new([ OFFICIAL_PLUGINS ||= Set.new([
"customer-flair", "customer-flair",
"discourse-adplugin", "discourse-adplugin",
"discourse-akismet", "discourse-akismet",

View File

@ -67,16 +67,14 @@ class TopicView
filter_posts(options) filter_posts(options)
if @posts if @posts
added_fields = User.whitelisted_user_custom_fields(@guardian) if (added_fields = User.whitelisted_user_custom_fields(@guardian)).present?
if added_fields.present?
@user_custom_fields = User.custom_fields_for_ids(@posts.map(&:user_id), added_fields) @user_custom_fields = User.custom_fields_for_ids(@posts.map(&:user_id), added_fields)
end end
end
whitelisted_fields = TopicView.whitelisted_post_custom_fields(@user) if (whitelisted_fields = TopicView.whitelisted_post_custom_fields(@user)).present?
if whitelisted_fields.present? && @posts
@post_custom_fields = Post.custom_fields_for_ids(@posts.map(&:id), whitelisted_fields) @post_custom_fields = Post.custom_fields_for_ids(@posts.map(&:id), whitelisted_fields)
end end
end
@draft_key = @topic.draft_key @draft_key = @topic.draft_key
@draft_sequence = DraftSequence.current(@user, @draft_key) @draft_sequence = DraftSequence.current(@user, @draft_key)