mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 20:12:45 +08:00
DEV: Use Set instead of array-as-an-object (#14511)
I don't know if JS engines were able to optimize-away those gigantic arrays but in any case that's a definite anti-pattern.
This commit is contained in:
parent
cd8a608d17
commit
d3a59e3f69
|
@ -43,12 +43,11 @@ const TopicList = RestModel.extend({
|
|||
canLoadMore: notEmpty("more_topics_url"),
|
||||
|
||||
forEachNew(topics, callback) {
|
||||
const topicIds = [];
|
||||
|
||||
this.topics.forEach((topic) => (topicIds[topic.id] = true));
|
||||
const topicIds = new Set();
|
||||
this.topics.forEach((topic) => topicIds.add(topic.id));
|
||||
|
||||
topics.forEach((topic) => {
|
||||
if (!topicIds[topic.id]) {
|
||||
if (!topicIds.has(topic.id)) {
|
||||
callback(topic);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -53,13 +53,12 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
|
|||
const url = `${getURL("/")}latest.json?topic_ids=${topic_ids.join(",")}`;
|
||||
|
||||
return ajax({ url, data: this.params }).then((result) => {
|
||||
const topicIds = [];
|
||||
|
||||
this.topics.forEach((topic) => (topicIds[topic.id] = true));
|
||||
const topicIds = new Set();
|
||||
this.topics.forEach((topic) => topicIds.add(topic.id));
|
||||
|
||||
let i = 0;
|
||||
TopicList.topicsFrom(store, result).forEach((topic) => {
|
||||
if (!topicIds[topic.id]) {
|
||||
if (!topicIds.has(topic.id)) {
|
||||
topic.set("highlight", true);
|
||||
this.topics.insertAt(i, topic);
|
||||
i++;
|
||||
|
|
Loading…
Reference in New Issue
Block a user