We have had a recurring problem on our Discourse forum for a while and we finally managed to narrow it down and reliably recreate it.
Here are the steps to recreate:
Have a topic with thousands of replies
Bookmark a post in that topic
Open the topic
The topic now takes a long time to load. In some cases it times out and we get an Ngnix error instead (502 Bad Gateway).
Here are some approximate loading times from our forum:
For a topic with about 1,000 replies, the extra loading time is a few seconds after a bookmark is created. Noticeable but not a huge problem.
For a topic with about 4,000 replies the loading time is usually 20-30 seconds and it sometimes times out instead of successfully loading the page.
For a topic with 9,000+ replies, it times out most of the time. In some cases it loads, but only after 30+ seconds.
Note that these topics load without any problem if we have no bookmarks in them. The problem only occurs for users who have bookmarks in a particular topic and as soon as they remove the bookmark the topic loads normally again.
I couldn’t repro your issue in topics with 30000 and 10000 replies on my forum.
If not too much of an inconvenience, could you try setting a timed reminder when setting the bookmark on step 2 in the reproduction description and see whether anything changes? That’s what finally made it reproducible for myself (specifically setting a reminder for “Monday” in my case).
This caused my .json-request related to the bookmarked post id to start delivering 302 after trying for 30 seconds, as seen in the image below. (occurs as I click on the bookmark-link on my profile menu).
By coincidence, I also noticed that search queries started exhibiting a similar behavior, although only slowing down immensely, once searching for anything in any subform, including those without any bookmarked posts what so ever.:
[Redacted image of slow search queries from Chromium dev tools as oly 1 embed was permitted]
From other experiences, it smells like some sort of SQL N+1-issue to me, but I’m far from well-versed enough in neither Discourse code nor Ruby itself to know whether perhaps a cyclic json model or similar would present itself in the same manner.
Can you repro this @martin?
Thanks for reporting this, I will try and repro and fix this week.