在自定义迁移后,许多永久链接指向了主题的第一篇帖子,而不是主题 URL 本身。
例如,永久链接指向
https://forum.example.com/t/example-topic/123/1
而不是
https://forum.example.com/t/example-topic/123
检查
如果以下 SQL 查询有记录,则表示 Discourse 论坛受到影响:
SELECT permalinks.*,
posts.id,
posts.topic_id,
posts.post_number
FROM permalinks
LEFT JOIN posts
ON posts.id = permalinks.post_id
WHERE permalinks.post_id IS NOT NULL
AND posts.post_number = 1
LIMIT 20;
快速修复
如果永久链接最初指向主题的第一篇帖子,此操作会将永久链接更改为直接指向主题。
UPDATE permalinks
SET topic_id = posts.topic_id,
post_id = NULL
FROM posts
WHERE permalinks.post_id = posts.id
AND permalinks.post_id IS NOT NULL
AND posts.post_number = 1;
这可能是一个在迁移脚本末尾运行的良好清理例程。