mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 00:32:52 +08:00
REFACTOR: idMap
should be a private API
This commit is contained in:
@ -257,7 +257,7 @@ Category.reopenClass({
|
|||||||
return Discourse.Site.currentProp("sortedCategories");
|
return Discourse.Site.currentProp("sortedCategories");
|
||||||
},
|
},
|
||||||
|
|
||||||
idMap() {
|
_idMap() {
|
||||||
return Discourse.Site.currentProp("categoriesById");
|
return Discourse.Site.currentProp("categoriesById");
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -273,7 +273,7 @@ Category.reopenClass({
|
|||||||
if (!id) {
|
if (!id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return Category.idMap()[id];
|
return Category._idMap()[id];
|
||||||
},
|
},
|
||||||
|
|
||||||
findByIds(ids = []) {
|
findByIds(ids = []) {
|
||||||
|
@ -410,12 +410,11 @@ const TopicTrackingState = EmberObject.extend({
|
|||||||
|
|
||||||
loadStates(data) {
|
loadStates(data) {
|
||||||
const states = this.states;
|
const states = this.states;
|
||||||
const idMap = Category.idMap();
|
|
||||||
|
|
||||||
// I am taking some shortcuts here to avoid 500 gets for a large list
|
// I am taking some shortcuts here to avoid 500 gets for a large list
|
||||||
if (data) {
|
if (data) {
|
||||||
data.forEach(topic => {
|
data.forEach(topic => {
|
||||||
var category = idMap[topic.category_id];
|
let category = Category.findById(topic.category_id);
|
||||||
if (category && category.parent_category_id) {
|
if (category && category.parent_category_id) {
|
||||||
topic.parent_category_id = category.parent_category_id;
|
topic.parent_category_id = category.parent_category_id;
|
||||||
}
|
}
|
||||||
|
@ -184,19 +184,6 @@ QUnit.test("findSingleBySlug", assert => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test("findByIds", assert => {
|
|
||||||
const store = createStore();
|
|
||||||
const categories = {
|
|
||||||
1: store.createRecord("category", { id: 1 }),
|
|
||||||
2: store.createRecord("category", { id: 2 })
|
|
||||||
};
|
|
||||||
|
|
||||||
sandbox.stub(Category, "idMap").returns(categories);
|
|
||||||
assert.deepEqual(Category.findByIds([1, 2, 3]), _.values(categories));
|
|
||||||
|
|
||||||
assert.deepEqual(Category.findByIds(), []);
|
|
||||||
});
|
|
||||||
|
|
||||||
QUnit.test("search with category name", assert => {
|
QUnit.test("search with category name", assert => {
|
||||||
const store = createStore(),
|
const store = createStore(),
|
||||||
category1 = store.createRecord("category", {
|
category1 = store.createRecord("category", {
|
||||||
|
Reference in New Issue
Block a user