mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +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
2 changed files with 6 additions and 8 deletions
|
@ -43,12 +43,11 @@ const TopicList = RestModel.extend({
|
||||||
canLoadMore: notEmpty("more_topics_url"),
|
canLoadMore: notEmpty("more_topics_url"),
|
||||||
|
|
||||||
forEachNew(topics, callback) {
|
forEachNew(topics, callback) {
|
||||||
const topicIds = [];
|
const topicIds = new Set();
|
||||||
|
this.topics.forEach((topic) => topicIds.add(topic.id));
|
||||||
this.topics.forEach((topic) => (topicIds[topic.id] = true));
|
|
||||||
|
|
||||||
topics.forEach((topic) => {
|
topics.forEach((topic) => {
|
||||||
if (!topicIds[topic.id]) {
|
if (!topicIds.has(topic.id)) {
|
||||||
callback(topic);
|
callback(topic);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -53,13 +53,12 @@ const DiscoveryCategoriesRoute = DiscourseRoute.extend(OpenComposer, {
|
||||||
const url = `${getURL("/")}latest.json?topic_ids=${topic_ids.join(",")}`;
|
const url = `${getURL("/")}latest.json?topic_ids=${topic_ids.join(",")}`;
|
||||||
|
|
||||||
return ajax({ url, data: this.params }).then((result) => {
|
return ajax({ url, data: this.params }).then((result) => {
|
||||||
const topicIds = [];
|
const topicIds = new Set();
|
||||||
|
this.topics.forEach((topic) => topicIds.add(topic.id));
|
||||||
this.topics.forEach((topic) => (topicIds[topic.id] = true));
|
|
||||||
|
|
||||||
let i = 0;
|
let i = 0;
|
||||||
TopicList.topicsFrom(store, result).forEach((topic) => {
|
TopicList.topicsFrom(store, result).forEach((topic) => {
|
||||||
if (!topicIds[topic.id]) {
|
if (!topicIds.has(topic.id)) {
|
||||||
topic.set("highlight", true);
|
topic.set("highlight", true);
|
||||||
this.topics.insertAt(i, topic);
|
this.topics.insertAt(i, topic);
|
||||||
i++;
|
i++;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue