Een bericht markeren in een groot onderwerp zorgt voor absurde laadtijden

Thanks to @sam’s advice I found that this is because of a poor query plan which is executed on this line:

topic.posts.with_deleted.where(post_number: 1).first

The SQL generated contains a LIMIT 1 which makes it so the index_posts_on_topic_id_and_post_number index is never used, causing a huge delay. I am unable to reproduce this locally because I have barely any posts in the local database; basically the more posts in your entire Discourse forum the worse this issue gets. I will have a fix up shortly.

3 likes