このコミットが含まれているのは:
@@ -57,6 +57,23 @@ RSpec.describe 'Posts API', type: :request do
|
||||
post_write_params({ base_version_no: base_version.version_no }.merge(params))
|
||||
end
|
||||
|
||||
def count_sql_queries
|
||||
count = 0
|
||||
|
||||
callback = lambda do |_name, _started, _finished, _id, payload|
|
||||
next if payload[:cached]
|
||||
next if ['SCHEMA', 'TRANSACTION'].include?(payload[:name])
|
||||
|
||||
count += 1
|
||||
end
|
||||
|
||||
ActiveSupport::Notifications.subscribed(callback, 'sql.active_record') do
|
||||
yield
|
||||
end
|
||||
|
||||
count
|
||||
end
|
||||
|
||||
let!(:tag_name) { TagName.create!(name: 'spec_tag') }
|
||||
let!(:tag) { Tag.create!(tag_name: tag_name, category: :general) }
|
||||
|
||||
@@ -558,6 +575,59 @@ RSpec.describe 'Posts API', type: :request do
|
||||
expect(sibling_ids).to include(sibling_post.id)
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not issue a query per tag or related post' do
|
||||
user = create_member_user!
|
||||
|
||||
tags =
|
||||
15.times.map do |i|
|
||||
tag_name = TagName.create!(name: "show_query_tag_#{ i }")
|
||||
tag = Tag.create!(tag_name:, category: :general)
|
||||
TagName.create!(name: "show_query_alias_#{ i }", canonical: tag_name)
|
||||
PostTag.create!(post: post_record, tag:)
|
||||
tag
|
||||
end
|
||||
|
||||
tags.each_cons(2) do |parent_tag, child_tag|
|
||||
TagImplication.create!(parent_tag:, tag: child_tag)
|
||||
end
|
||||
|
||||
parent_post = Post.create!(
|
||||
title: 'query parent post',
|
||||
url: 'https://example.com/query-parent-post'
|
||||
)
|
||||
sibling_post = Post.create!(
|
||||
title: 'query sibling post',
|
||||
url: 'https://example.com/query-sibling-post'
|
||||
)
|
||||
child_post = Post.create!(
|
||||
title: 'query child post',
|
||||
url: 'https://example.com/query-child-post'
|
||||
)
|
||||
|
||||
PostImplication.create!(post: post_record, parent_post:)
|
||||
PostImplication.create!(post: sibling_post, parent_post:)
|
||||
PostImplication.create!(post: child_post, parent_post: post_record)
|
||||
|
||||
20.times do |i|
|
||||
related_post = Post.create!(
|
||||
title: "query related post #{ i }",
|
||||
url: "https://example.com/query-related-post-#{ i }"
|
||||
)
|
||||
PostSimilarity.create!(post: post_record,
|
||||
target_post: related_post,
|
||||
cos: 1.0 - (i / 100.0))
|
||||
end
|
||||
|
||||
query_count =
|
||||
count_sql_queries do
|
||||
get "/posts/#{ post_record.id }",
|
||||
headers: { 'X-Transfer-Code' => user.inheritance_code }
|
||||
end
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(query_count).to be <= 45
|
||||
end
|
||||
end
|
||||
|
||||
context 'when post does not exist' do
|
||||
|
||||
新しい課題から参照
ユーザをブロックする