mirror of
https://github.com/discourse/discourse.git
synced 2025-09-07 12:02:53 +08:00
Refactor select().map() to use pluck.
Remove a method already provided by ActiveRecord.
This commit is contained in:
parent
d30330441a
commit
5659b66729
4 changed files with 4 additions and 8 deletions
|
@ -112,7 +112,7 @@ class Category < ActiveRecord::Base
|
||||||
def group_names=(names)
|
def group_names=(names)
|
||||||
# this line bothers me, destroying in AR can not seem to be queued, thinking of extending it
|
# this line bothers me, destroying in AR can not seem to be queued, thinking of extending it
|
||||||
category_groups.destroy_all unless new_record?
|
category_groups.destroy_all unless new_record?
|
||||||
ids = Group.where(name: names.split(",")).select(:id).map(&:id)
|
ids = Group.where(name: names.split(",")).pluck(:id)
|
||||||
ids.each do |id|
|
ids.each do |id|
|
||||||
category_groups.build(group_id: id)
|
category_groups.build(group_id: id)
|
||||||
end
|
end
|
||||||
|
|
|
@ -129,11 +129,7 @@ class Group < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def usernames
|
def usernames
|
||||||
users.select("username").map(&:username).join(",")
|
users.pluck(:username).join(",")
|
||||||
end
|
|
||||||
|
|
||||||
def user_ids
|
|
||||||
users.select('users.id').map(&:id)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def add(user)
|
def add(user)
|
||||||
|
|
|
@ -26,7 +26,7 @@ class PostAction < ActiveRecord::Base
|
||||||
.count('DISTINCT posts.id')
|
.count('DISTINCT posts.id')
|
||||||
|
|
||||||
$redis.set('posts_flagged_count', posts_flagged_count)
|
$redis.set('posts_flagged_count', posts_flagged_count)
|
||||||
user_ids = User.staff.select(:id).map {|u| u.id}
|
user_ids = User.staff.pluck(:id)
|
||||||
MessageBus.publish('/flagged_counts', { total: posts_flagged_count }, { user_ids: user_ids })
|
MessageBus.publish('/flagged_counts', { total: posts_flagged_count }, { user_ids: user_ids })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ class PostDestroyer
|
||||||
@post.update_flagged_posts_count
|
@post.update_flagged_posts_count
|
||||||
|
|
||||||
# Remove any reply records that point to deleted posts
|
# Remove any reply records that point to deleted posts
|
||||||
post_ids = PostReply.select(:post_id).where(reply_id: @post.id).map(&:post_id)
|
post_ids = PostReply.where(reply_id: @post.id).pluck(:post_id)
|
||||||
PostReply.delete_all reply_id: @post.id
|
PostReply.delete_all reply_id: @post.id
|
||||||
|
|
||||||
if post_ids.present?
|
if post_ids.present?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue