This thread in particular had been bugging me for a very long time. I asked, why is it taking from 1-3 minutes to load, if it even decides to load?
After seeing someone second this issue in this post, I decided to look into it: I removed all bookmarks from the thread with 4,500 posts.
It loaded instantly like any other post would.
I then asked myself, what other ways could I test this?
Irregardless of whether or not I bookmarked the first post or the latest post, it still took a while to load, albeit not minutes but around 10 seconds.
The effect was exacerbated on threads with more posts; I feel like there’s a certain threshold around 4000 posts that makes loading times this slow.
I tested this on other threads with more than 4000 posts.
The more bookmarks a topic has, the longer it takes to load.
I theorize that the more bookmarks you have on a topic with many posts, the longer it takes to load.
To repro: Open up a topic with many, many posts and bookmark one. It’s too bad that the referenced thread needs you to sign in to bookmark a post, and that the thread with the most amount of replies on this website is 925.
If I need to provide any more information, go ahead and ask.
However, I made a topic with 5000 posts locally and made a bookmark, and it loads in the same time whether I have a bookmark in the topic or not . I will have to keep looking…the code that loads the bookmarks for a user in a topic is here:
To me this does not look crazy and performance intensive. user_post_bookmarks will only query the database once because it is memoized, so no N1 issue here. Also here is the topic view code to see if there is a bookmark at the topic level:
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.