הצג רשימת נושאים על פי מערך של מזהי נושאים

סיכום מבוסס בינה מלאכותית

The discussion revolves around fetching a list of topics or posts from Discourse by providing an array of topic IDs, ideally in a predefined order. adopilot seeks a way to query Discourse via an endpoint with an array of topic IDs to retrieve topics efficiently, as their ERP system integrates with Discourse and requires this functionality. spirobel shares a similar need and initially implemented a slow solution by fetching topics individually. They later developed a workaround using TopicList.topics_array() to fetch multiple topics in bulk, though it doesn’t return full Topic objects. They also considered optimizing by checking the store first and using fromMap, but acknowledge potential security concerns. spirobel shares their final solution via a GitHub commit, noting that while functional, it may not be the most secure or ideal approach. The thread highlights a gap in Discourse’s API for bulk topic retrieval and seeks a more efficient, built-in solution.

In our company we use discourse for everyday business.
Discourse is deeply integrated in our erp software.
For better organization of topics,our erp holds many kind of topics ids and posts ids.
In some parts of our app we want to show user list of specific topics in discource. (filtered by our citiera).
In our app there is form which users fills and our app has array of filtered topics.

Is there a way to send query string or formdata to discource endpoint among with array of wanted topics ids and to get list of topics in discource. (ideally with predefined order or ordered as array was)

Same needs we have for getting specific lists of posts by providing array of topics ids.

I also need this functionality. right now I am doing it like this, but this takes way too long.

    const selectedTopics = this.selectedTopics
     //eat topics as ids and let out real topics
     this.selectedTopicsID.forEach(function(tid,index){
       Topic.find(tid,{}).then(results => {
         selectedTopics.pushObject(results)
       })
     });

I am about to reopen the listcontroller in my plugin.rb and add a new endpoint and reopen the topic-list in the frontend initializer and do something similar to this:

https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/models/topic-list.js.es6#L129
But there must be an easier way to do this. Is there really no endpoint yet to fetch topics in bulk by id?
I would be very glad for some help :smiley:
EDIT: This is how I solved this problem for me:
https://github.com/spirobel/projects/commit/b514a366f05005888805fc2f57118dfd9fd61fa1
This is how it can be used.

import TopicList from 'discourse/models/topic-list';
    const selectedTopics = this.selectedTopics
    //eat topics as ids
    TopicList.topics_array(this.selectedTopicsID).then(results => selectedTopics.pushObjects(results.topic_list.topics))

right now this still has the downside, that it doesnt return “real” Topic objects, but I guess adding a line like this will fix it:

I am still unsure if this is the right way to do it and/or if this breaks security.
Another thing that could be done: first look in the store if the record is already there and then only load what isnt there, with fromMap. Similar to:

anyways this is getting to verbose here :smiley:
This is my final solution I will call it a day now:
https://github.com/spirobel/projects/commit/004da260f15486bf71ca48fa7c6ecee11ce646f0