The discussion revolves around the issue of topic slugs being translated into topic IDs on a Discourse server. pontus.dualdecade explains that their server uses topic slugs like 123-region-2, but recently, if the slug does not exist, the server retrieves the topic with the matching topic ID. codinghorror questions why the URL is malformed and suggests the correct format should include the numeric ID of the topic.
pfaffman explains that starting a title with a number is a bad idea, as the slug is ignored by Discourse, and if the number matches a topic ID, it will retrieve that topic. pontus.dualdecade clarifies that they lazily predict the topic slug and have no way of predicting the internal Discourse topic ID. pfaffman suggests changing the slug to avoid starting with numbers or using the API to get the topic ID by topic slug.
The conversation concludes with pontus.dualdecade joking about having to rename 37,000 topic slugs, and pfaffman offering to help with the task. codinghorror questions why the original approach was taken, and pfaffman acknowledges getting lost in the discussion.
So, on our discourse server we use topic slugs like 123-region-2 this has been no issue until recently. Now it seems thats the discourse server, if it gets a request for example 5454-region-3 and that topic slug does not exist. It gets the topic with topic id 5454 and this creates a lot of problems.
Was there an update to this behaviour recently? We usually run launcher rebuild close to once a week so we have 2.3.0.beta5 right now.
Another theory might be that our 123 part in 123-region-2 is always higher than topic ids and they both have just been increasing causing no “collisions” but now that we added another region which starts of from 0 again we almost exclusively get collisions with existing topics.
Is there a way to make sure if we get http://discourse.server.com/t/123-mytopicslug-2.json and that topic does not exist we get a 404?
Starting a title with a number is a bad idea as you describe. The problem is that the slug is ignored by Discourse and that if you start a slug with a number and that number matches a topic_id you’ll get that topic.
We do this lazily, so the client predicts the topic slug. We have no way of predicting the internal discourse topic id.
So we have to get the topic solely based on the slug.
If we change the slug to be region-1-123 instead and that works I guess thats a solution. To clarify, the numbers 1 and 123 here has nothing to do with discourse and are generated elsewhere.
Or, if there is a way to get topic id by topic slug only that would be great in our case.
Renaming 37K topics could be done with a script. If you have a budget for such, post on Marketplace or contact me directly.
Re-training your users to guess new URLs, which would seem much harder. But how did you train them to guess URLs in the first place? Are they coming from some other site that you manage?