mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 02:48:28 +08:00
speed up tests
add the ability to find the first notify private message
This commit is contained in:
@ -270,7 +270,26 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def url
|
||||
"/t/#{Slug.for(topic.title)}/#{topic.id}/#{post_number}"
|
||||
Post.url(topic.title, topic.id, post_number)
|
||||
end
|
||||
|
||||
def self.url(title, topic_id, post_number)
|
||||
"/t/#{Slug.for(title)}/#{topic_id}/#{post_number}"
|
||||
end
|
||||
|
||||
def self.urls(post_ids)
|
||||
ids = post_ids.map{|u| u}
|
||||
if ids.length > 0
|
||||
urls = {}
|
||||
Topic.joins(:posts).where('posts.id' => ids).
|
||||
select(['posts.id as post_id','post_number', 'topics.title', 'topics.id']).
|
||||
each do |t|
|
||||
urls[t.post_id.to_i] = url(t.title, t.id, t.post_number)
|
||||
end
|
||||
urls
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
||||
def author_readable
|
||||
|
@ -6,7 +6,7 @@ class PostAction < ActiveRecord::Base
|
||||
|
||||
include RateLimiter::OnCreateRecord
|
||||
|
||||
attr_accessible :post_action_type_id, :post_id, :user_id, :post, :user, :post_action_type, :message
|
||||
attr_accessible :post_action_type_id, :post_id, :user_id, :post, :user, :post_action_type, :message, :related_post_id
|
||||
|
||||
belongs_to :post
|
||||
belongs_to :user
|
||||
@ -89,16 +89,21 @@ class PostAction < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
related_post_id = nil
|
||||
if target_usernames.present?
|
||||
PostCreator.new(user,
|
||||
related_post_id = PostCreator.new(user,
|
||||
target_usernames: target_usernames,
|
||||
archetype: Archetype.private_message,
|
||||
subtype: subtype,
|
||||
title: title,
|
||||
raw: body
|
||||
).create
|
||||
).create.id
|
||||
end
|
||||
create(post_id: post.id, user_id: user.id, post_action_type_id: post_action_type_id, message: message)
|
||||
create( post_id: post.id,
|
||||
user_id: user.id,
|
||||
post_action_type_id: post_action_type_id,
|
||||
message: message,
|
||||
related_post_id: related_post_id )
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
# can happen despite being .create
|
||||
# since already bookmarked
|
||||
|
Reference in New Issue
Block a user