PERF: stop destroying drafts on client when posting replies

The server already ensures it advances draft keys when a post is created
this means this code that used to delete drafts is simply introducing
composer delays with no benefit.
This commit is contained in:
Sam Saffron 2019-10-29 17:07:33 +11:00
parent b92e4465f7
commit 492742837e
1 changed files with 22 additions and 36 deletions

View File

@ -687,47 +687,33 @@ export default Controller.extend({
});
}
// If user "created a new topic/post" or "replied as a new topic" successfully, remove the draft.
let destroyDraftPromise;
if (result.responseJson.action === "create_post") {
destroyDraftPromise = this.destroyDraft();
if (this.get("model.editingPost")) {
this.appEvents.trigger("post-stream:refresh", {
id: parseInt(result.responseJson.id)
});
if (result.responseJson.post.post_number === 1) {
this.appEvents.trigger("header:update-topic", composer.topic);
}
} else {
destroyDraftPromise = Ember.RSVP.Promise.resolve();
this.appEvents.trigger("post-stream:refresh");
}
return destroyDraftPromise.then(() => {
if (this.get("model.editingPost")) {
this.appEvents.trigger("post-stream:refresh", {
id: parseInt(result.responseJson.id)
});
if (result.responseJson.post.post_number === 1) {
this.appEvents.trigger("header:update-topic", composer.topic);
}
} else {
this.appEvents.trigger("post-stream:refresh");
}
if (result.responseJson.action === "create_post") {
this.appEvents.trigger("post:highlight", result.payload.post_number);
}
this.close();
if (result.responseJson.action === "create_post") {
this.appEvents.trigger(
"post:highlight",
result.payload.post_number
);
}
this.close();
const currentUser = this.currentUser;
if (composer.creatingTopic) {
currentUser.set("topic_count", currentUser.topic_count + 1);
} else {
currentUser.set("reply_count", currentUser.reply_count + 1);
}
const currentUser = this.currentUser;
if (composer.creatingTopic) {
currentUser.set("topic_count", currentUser.topic_count + 1);
} else {
currentUser.set("reply_count", currentUser.reply_count + 1);
}
const post = result.target;
if (post && !staged) {
DiscourseURL.routeTo(post.url);
}
});
const post = result.target;
if (post && !staged) {
DiscourseURL.routeTo(post.url);
}
})
.catch(error => {
composer.set("disableDrafts", false);