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

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. if (this.get("model.editingPost")) {
let destroyDraftPromise; this.appEvents.trigger("post-stream:refresh", {
id: parseInt(result.responseJson.id)
if (result.responseJson.action === "create_post") { });
destroyDraftPromise = this.destroyDraft(); if (result.responseJson.post.post_number === 1) {
this.appEvents.trigger("header:update-topic", composer.topic);
}
} else { } else {
destroyDraftPromise = Ember.RSVP.Promise.resolve(); this.appEvents.trigger("post-stream:refresh");
} }
return destroyDraftPromise.then(() => { if (result.responseJson.action === "create_post") {
if (this.get("model.editingPost")) { this.appEvents.trigger("post:highlight", result.payload.post_number);
this.appEvents.trigger("post-stream:refresh", { }
id: parseInt(result.responseJson.id) this.close();
});
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") { const currentUser = this.currentUser;
this.appEvents.trigger( if (composer.creatingTopic) {
"post:highlight", currentUser.set("topic_count", currentUser.topic_count + 1);
result.payload.post_number } else {
); currentUser.set("reply_count", currentUser.reply_count + 1);
} }
this.close();
const currentUser = this.currentUser; const post = result.target;
if (composer.creatingTopic) { if (post && !staged) {
currentUser.set("topic_count", currentUser.topic_count + 1); DiscourseURL.routeTo(post.url);
} else { }
currentUser.set("reply_count", currentUser.reply_count + 1);
}
const post = result.target;
if (post && !staged) {
DiscourseURL.routeTo(post.url);
}
});
}) })
.catch(error => { .catch(error => {
composer.set("disableDrafts", false); composer.set("disableDrafts", false);