FIX: stop memoize PostActionTypes (#28005)

Memoizing all_flags on PostActionType was a mistake. This commit brings back the cache on the serialize level.
This commit is contained in:
Krzysztof Kotlarek
2024-07-22 17:35:49 +10:00
committed by GitHub
parent 5105fce899
commit fb7cc2d375
6 changed files with 84 additions and 11 deletions

View File

@@ -290,7 +290,10 @@ class PostSerializer < BasicPostSerializer
result = []
can_see_post = scope.can_see_post?(object)
PostActionType.types.each do |sym, id|
public_flag_types =
(@topic_view.present? ? @topic_view.public_flag_types : PostActionType.public_types)
(@topic_view.present? ? @topic_view.flag_types : PostActionType.types).each do |sym, id|
count_col = "#{sym}_count".to_sym
count = object.public_send(count_col) if object.respond_to?(count_col)
@@ -301,6 +304,22 @@ class PostSerializer < BasicPostSerializer
sym,
opts: {
taken_actions: actions,
notify_flag_types:
(
if @topic_view.present?
@topic_view.notify_flag_types
else
PostActionType.notify_flag_types
end
),
additional_message_types:
(
if @topic_view.present?
@topic_view.additional_message_types
else
PostActionType.additional_message_types
end
),
},
can_see_post: can_see_post,
)
@@ -327,7 +346,7 @@ class PostSerializer < BasicPostSerializer
end
# only show public data
unless scope.is_staff? || PostActionType.public_types.values.include?(id)
unless scope.is_staff? || public_flag_types.values.include?(id)
summary[:count] = summary[:acted] ? 1 : 0
end