preload email correctly (not backwards compat with stable)

This commit is contained in:
Sam 2017-08-29 12:49:31 -04:00
parent 1c70a81ac4
commit 70911cbd43
2 changed files with 21 additions and 11 deletions

View File

@ -20,9 +20,9 @@ after_initialize do
def self.backfill_auto_assign def self.backfill_auto_assign
staff_mention = User.where('moderator OR admin') staff_mention = User.where('moderator OR admin')
.pluck('username') .pluck('username')
.map{|name| "p.cooked ILIKE '%mention%@#{name}%'"} .map { |name| "p.cooked ILIKE '%mention%@#{name}%'" }
.join(' OR ') .join(' OR ')
sql = <<SQL sql = <<SQL
SELECT p.topic_id, MAX(post_number) post_number SELECT p.topic_id, MAX(post_number) post_number
@ -263,15 +263,16 @@ SQL
allowed_access = SiteSetting.assigns_public || is_staff allowed_access = SiteSetting.assigns_public || is_staff
if allowed_access && topics.length > 0 if allowed_access && topics.length > 0
users = User.where("id in ( users = User.where("users.id in (
SELECT value::int SELECT value::int
FROM topic_custom_fields FROM topic_custom_fields
WHERE name = 'assigned_to_id' AND topic_id IN (?) WHERE name = 'assigned_to_id' AND topic_id IN (?)
)", topics.map(&:id)) )", topics.map(&:id))
.select(:id, :email, :username, :uploaded_avatar_id) .joins('join user_emails on user_emails.user_id = users.id AND user_emails.primary')
.select(:id, 'user_emails.email', :username, :uploaded_avatar_id)
map = {} map = {}
users.each{|u| map[u.id] = u} users.each { |u| map[u.id] = u }
topics.each do |t| topics.each do |t|
if id = t.custom_fields['assigned_to_id'] if id = t.custom_fields['assigned_to_id']
@ -300,7 +301,7 @@ SQL
results = results.joins("LEFT JOIN topic_custom_fields tc_assign ON results = results.joins("LEFT JOIN topic_custom_fields tc_assign ON
topics.id = tc_assign.topic_id AND topics.id = tc_assign.topic_id AND
tc_assign.name = 'assigned_to_id'") tc_assign.name = 'assigned_to_id'")
.where("tc_assign.name IS NULL") .where("tc_assign.name IS NULL")
else else
if username == "*" if username == "*"
@ -352,7 +353,7 @@ SQL
end end
def include_assigned_to_user? def include_assigned_to_user?
if SiteSetting.assigns_public || scope.is_staff? if SiteSetting.assigns_public || scope.is_staff?
# subtle but need to catch cases where stuff is not assigned # subtle but need to catch cases where stuff is not assigned
object.topic.custom_fields.keys.include?("assigned_to_id") object.topic.custom_fields.keys.include?("assigned_to_id")
end end
@ -389,12 +390,10 @@ SQL
Discourse::Application.routes.append do Discourse::Application.routes.append do
mount ::DiscourseAssign::Engine, at: "/assign" mount ::DiscourseAssign::Engine, at: "/assign"
get "topics/private-messages-assigned/:username" => "list#private_messages_assigned", get "topics/private-messages-assigned/:username" => "list#private_messages_assigned", as: "topics_private_messages_assigned", constraints: { username: /[\w.\-]+?/ }
as: "topics_private_messages_assigned", constraints: {username: /[\w.\-]+?/}
end end
end end
on(:post_created) do |post| on(:post_created) do |post|
::TopicAssigner.auto_assign(post, force: true) ::TopicAssigner.auto_assign(post, force: true)
end end

View File

@ -0,0 +1,11 @@
require 'rails_helper'
describe 'integration tests' do
it 'preloads data in topic list' do
admin = Fabricate(:admin)
post = create_post
list = TopicList.new("latest", admin, [post.topic])
TopicList.preload([post.topic], list)
# should not explode for now
end
end