FIX: Don't overwrite Topic.category computed prop (#18)

Pre-loading/pre-assigning isn't necessary. `Topic.category` uses `Category.findById` which in turn uses an identity map, so there are no N+1 calls to the backend.
This commit is contained in:
Jarek Radosz 2020-11-11 22:14:38 +01:00 committed by GitHub
parent 23ed78cc87
commit 019591c995
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 26 deletions

View File

@ -1,22 +1,9 @@
import Controller from "@ember/controller";
import discourseComputed from "discourse-common/utils/decorators";
import Category from "discourse/models/category";
import { on } from "discourse-common/utils/decorators";
import KnowledgeExplorer from "discourse/plugins/discourse-knowledge-explorer/discourse/models/knowledge-explorer";
import { getOwner } from "@ember/application";
function mergeCategories(results) {
const categories = Category.list();
const topics = results.topics.topic_list.topics.map((t) => {
t.category = categories.findBy("id", t.category_id);
return t;
});
results.topics.topic_list.topics = topics;
return results;
}
export default Controller.extend({
queryParams: {
ascending: "ascending",
@ -184,7 +171,6 @@ export default Controller.extend({
this.set("isLoadingMore", true);
KnowledgeExplorer.loadMore(this.loadMoreUrl).then((result) => {
result = mergeCategories(result);
const topics = this.topics.concat(result.topics.topic_list.topics);
this.setProperties({

View File

@ -1,5 +1,4 @@
import Route from "@ember/routing/route";
import Category from "discourse/models/category";
import KnowledgeExplorer from "discourse/plugins/discourse-knowledge-explorer/discourse/models/knowledge-explorer";
export default Route.extend({
@ -24,17 +23,6 @@ export default Route.extend({
},
setupController(controller, model) {
const categories = Category.list();
let topics = model.topics.topic_list.topics;
topics = topics.map((t) => {
t.category = categories.findBy("id", t.category_id);
return t;
});
model.topics.topic_list.topics = topics;
controller.set("topic", model.topic);
controller.set("model", model);
},