このコミットが含まれているのは:
2026-06-07 01:24:44 +09:00
コミット 39d86f4778
4個のファイルの変更33行の追加33行の削除
+15 -25
ファイルの表示
@@ -24,11 +24,9 @@ class TheatrePostSelector
candidates = weighted_candidates
sorted = candidates.sort_by { |candidate| [candidate.weight, candidate.post.id] }
{
tag_penalties: tag_penalty_json,
{ tag_penalties: tag_penalty_json,
lightest_posts: post_weight_json(sorted.first(limit)),
heaviest_posts: post_weight_json(sorted.reverse.first(limit))
}
heaviest_posts: post_weight_json(sorted.reverse.first(limit)) }
end
private
@@ -45,11 +43,10 @@ class TheatrePostSelector
penalty = post_tags.sum { |tag| penalties[tag.id].to_i }
Candidate.new(
post:,
penalty:,
tags: post_tags,
weight: 1.0 / (1.0 + penalty)
)
post:,
penalty:,
tags: post_tags,
weight: 1.0 / (1.0 + penalty))
end
end
end
@@ -87,10 +84,8 @@ class TheatrePostSelector
tag = tags[tag_id]
next unless tag
{
tag: light_tag_json(tag),
penalty:
}
{ tag: light_tag_json(tag),
penalty: }
}
.compact
.sort_by { |row| [-row[:penalty], row[:tag][:name].to_s] }
@@ -98,27 +93,22 @@ class TheatrePostSelector
def post_weight_json candidates
candidates.map { |candidate|
{
post: light_post_json(candidate.post),
{ post: light_post_json(candidate.post),
weight: candidate.weight,
penalty: candidate.penalty,
tags: candidate.tags.map { |tag| light_tag_json(tag) }
}
tags: candidate.tags.map { |tag| light_tag_json(tag) } }
}
end
def light_post_json post
{
id: post.id,
{ id: post.id,
title: post.title,
url: post.url
}
url: post.url }
end
def light_tag_json tag
{
id: tag.id,
name: tag.name
}
{ id: tag.id,
name: tag.name,
category: tag.category }
end
end