DEV: Replace Category.findById with Category.asyncFindByIds in easy cases (#26270)
This commit is contained in:
parent
1df97e86c1
commit
cafdc29806
|
@ -22,6 +22,7 @@ export class MultiCache {
|
||||||
this.fetchTimes = [this.fetchTimes[this.fetchTimes.length - 1], new Date()];
|
this.fetchTimes = [this.fetchTimes[this.fetchTimes.length - 1], new Date()];
|
||||||
|
|
||||||
const notFound = [];
|
const notFound = [];
|
||||||
|
ids = ids.uniq();
|
||||||
|
|
||||||
for (const id of ids) {
|
for (const id of ids) {
|
||||||
if (!this.values.has(id)) {
|
if (!this.values.has(id)) {
|
||||||
|
|
|
@ -190,26 +190,27 @@ export default class History extends Component {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
revert(post, postVersion) {
|
async revert(post, postVersion) {
|
||||||
post
|
try {
|
||||||
.revertToRevision(postVersion)
|
const result = await post.revertToRevision(postVersion);
|
||||||
.then((result) => {
|
this.refresh(post.id, postVersion);
|
||||||
this.refresh(post.id, postVersion);
|
if (result.topic) {
|
||||||
if (result.topic) {
|
post.set("topic.slug", result.topic.slug);
|
||||||
post.set("topic.slug", result.topic.slug);
|
post.set("topic.title", result.topic.title);
|
||||||
post.set("topic.title", result.topic.title);
|
post.set("topic.fancy_title", result.topic.fancy_title);
|
||||||
post.set("topic.fancy_title", result.topic.fancy_title);
|
}
|
||||||
}
|
if (result.category_id) {
|
||||||
if (result.category_id) {
|
post.set(
|
||||||
post.set("topic.category", Category.findById(result.category_id));
|
"topic.category",
|
||||||
}
|
await Category.asyncFindById(result.category_id)
|
||||||
this.args.closeModal();
|
);
|
||||||
})
|
}
|
||||||
.catch((e) => {
|
this.args.closeModal();
|
||||||
if (e.jqXHR.responseJSON?.errors?.[0]) {
|
} catch (e) {
|
||||||
this.dialog.alert(e.jqXHR.responseJSON.errors[0]);
|
if (e.jqXHR.responseJSON?.errors?.[0]) {
|
||||||
}
|
this.dialog.alert(e.jqXHR.responseJSON.errors[0]);
|
||||||
});
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get editButtonLabel() {
|
get editButtonLabel() {
|
||||||
|
|
|
@ -157,6 +157,10 @@ export default class Category extends RestModel {
|
||||||
return categories;
|
return categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async asyncFindById(id) {
|
||||||
|
return (await Category.asyncFindByIds([id]))[0];
|
||||||
|
}
|
||||||
|
|
||||||
static findBySlugAndParent(slug, parentCategory) {
|
static findBySlugAndParent(slug, parentCategory) {
|
||||||
if (this.slugEncoded()) {
|
if (this.slugEncoded()) {
|
||||||
slug = encodeURI(slug);
|
slug = encodeURI(slug);
|
||||||
|
|
|
@ -450,7 +450,7 @@ export default class Group extends RestModel {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
findPosts(opts) {
|
async findPosts(opts) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
const type = opts.type || "posts";
|
const type = opts.type || "posts";
|
||||||
const data = {};
|
const data = {};
|
||||||
|
@ -463,13 +463,16 @@ export default class Group extends RestModel {
|
||||||
data.category_id = parseInt(opts.categoryId, 10);
|
data.category_id = parseInt(opts.categoryId, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ajax(`/groups/${this.name}/${type}.json`, { data }).then((posts) => {
|
const posts = await ajax(`/groups/${this.name}/${type}.json`, { data });
|
||||||
return posts.map((p) => {
|
const categories = await Category.asyncFindByIds(
|
||||||
p.user = User.create(p.user);
|
posts.map((p) => p.category_id)
|
||||||
p.topic = Topic.create(p.topic);
|
);
|
||||||
p.category = Category.findById(p.category_id);
|
|
||||||
return EmberObject.create(p);
|
return posts.map((p) => {
|
||||||
});
|
p.user = User.create(p.user);
|
||||||
|
p.topic = Topic.create(p.topic);
|
||||||
|
p.category = categories[p.category_id];
|
||||||
|
return EmberObject.create(p);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue