FIX: Backup logs were usually missing the first few lines

And because of debouncing, the log wasn't always reset at the beginning of a backup or restore.
This commit is contained in:
Gerhard Schlager 2018-09-19 20:00:03 +02:00
parent 18d5d51d98
commit 681262ddce
5 changed files with 44 additions and 51 deletions

View File

@ -2,6 +2,7 @@ import debounce from "discourse/lib/debounce";
import { renderSpinner } from "discourse/helpers/loading-spinner"; import { renderSpinner } from "discourse/helpers/loading-spinner";
import { escapeExpression } from "discourse/lib/utilities"; import { escapeExpression } from "discourse/lib/utilities";
import { bufferedRender } from "discourse-common/lib/buffered-render"; import { bufferedRender } from "discourse-common/lib/buffered-render";
import { observes, on } from "ember-addons/ember-computed-decorators";
export default Ember.Component.extend( export default Ember.Component.extend(
bufferedRender({ bufferedRender({
@ -21,11 +22,21 @@ export default Ember.Component.extend(
$div.scrollTop = $div.scrollHeight; $div.scrollTop = $div.scrollHeight;
}, },
@on("init")
@observes("logs.[]")
_resetFormattedLogs() {
if (this.get("logs").length === 0) {
this._reset(); // reset the cached logs whenever the model is reset
this.rerenderBuffer();
}
},
@on("init")
@observes("logs.[]")
_updateFormattedLogs: debounce(function() { _updateFormattedLogs: debounce(function() {
const logs = this.get("logs"); const logs = this.get("logs");
if (logs.length === 0) { if (logs.length === 0) return;
this._reset(); // reset the cached logs whenever the model is reset
} else {
// do the log formatting only once for HELLish performance // do the log formatting only once for HELLish performance
let formattedLogs = this.get("formattedLogs"); let formattedLogs = this.get("formattedLogs");
for (let i = this.get("index"), length = logs.length; i < length; i++) { for (let i = this.get("index"), length = logs.length; i < length; i++) {
@ -40,11 +51,9 @@ export default Ember.Component.extend(
}); });
// force rerender // force rerender
this.rerenderBuffer(); this.rerenderBuffer();
}
Ember.run.scheduleOnce("afterRender", this, this._scrollDown); Ember.run.scheduleOnce("afterRender", this, this._scrollDown);
}, 150) }, 150),
.observes("logs.[]")
.on("init"),
buildBuffer(buffer) { buildBuffer(buffer) {
const formattedLogs = this.get("formattedLogs"); const formattedLogs = this.get("formattedLogs");

View File

@ -1,24 +1,17 @@
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
import Backup from "admin/models/backup";
export default Ember.Controller.extend(ModalFunctionality, { export default Ember.Controller.extend(ModalFunctionality, {
adminBackupsLogs: Ember.inject.controller(), adminBackupsLogs: Ember.inject.controller(),
_startBackup(withUploads) {
this.currentUser.set("hideReadOnlyAlert", true);
Backup.start(withUploads).then(() => {
this.get("adminBackupsLogs.logs").clear();
this.send("backupStarted");
});
},
actions: { actions: {
startBackup() { startBackupWithUploads() {
this._startBackup(); this.send("closeModal");
this.send("startBackup", true);
}, },
startBackupWithoutUpload() { startBackupWithoutUploads() {
this._startBackup(false); this.send("closeModal");
this.send("startBackup", false);
}, },
cancel() { cancel() {

View File

@ -10,6 +10,7 @@ export default Discourse.Route.extend({
activate() { activate() {
this.messageBus.subscribe(LOG_CHANNEL, log => { this.messageBus.subscribe(LOG_CHANNEL, log => {
if (log.message === "[STARTED]") { if (log.message === "[STARTED]") {
Discourse.User.currentProp("hideReadOnlyAlert", true);
this.controllerFor("adminBackups").set( this.controllerFor("adminBackups").set(
"model.isOperationRunning", "model.isOperationRunning",
true true
@ -62,15 +63,14 @@ export default Discourse.Route.extend({
}, },
actions: { actions: {
startBackup() { showStartBackupModal() {
showModal("admin-start-backup", { admin: true }); showModal("admin-start-backup", { admin: true });
this.controllerFor("modal").set("modalClass", "start-backup-modal"); this.controllerFor("modal").set("modalClass", "start-backup-modal");
}, },
backupStarted() { startBackup(withUploads) {
this.controllerFor("adminBackups").set("isOperationRunning", true);
this.transitionTo("admin.backups.logs"); this.transitionTo("admin.backups.logs");
this.send("closeModal"); Backup.start(withUploads);
}, },
destroyBackup(backup) { destroyBackup(backup) {
@ -100,17 +100,8 @@ export default Discourse.Route.extend({
I18n.t("yes_value"), I18n.t("yes_value"),
function(confirmed) { function(confirmed) {
if (confirmed) { if (confirmed) {
Discourse.User.currentProp("hideReadOnlyAlert", true);
backup.restore().then(function() {
self
.controllerFor("adminBackupsLogs")
.get("logs")
.clear();
self
.controllerFor("adminBackups")
.set("model.isOperationRunning", true);
self.transitionTo("admin.backups.logs"); self.transitionTo("admin.backups.logs");
}); backup.restore();
} }
} }
); );

View File

@ -21,7 +21,7 @@
label="admin.backups.operations.cancel.label" label="admin.backups.operations.cancel.label"
icon="times"}} icon="times"}}
{{else}} {{else}}
{{d-button action="startBackup" {{d-button action="showStartBackupModal"
class="btn-primary" class="btn-primary"
title="admin.backups.operations.backup.title" title="admin.backups.operations.backup.title"
label="admin.backups.operations.backup.label" label="admin.backups.operations.backup.label"

View File

@ -1,5 +1,5 @@
{{#d-modal-body title="admin.backups.operations.backup.confirm"}} {{#d-modal-body title="admin.backups.operations.backup.confirm"}}
<button {{action "startBackup"}} class="btn btn-primary">{{i18n 'yes_value'}}</button> <button {{action "startBackupWithUploads"}} class="btn btn-primary">{{i18n 'yes_value'}}</button>
<button {{action "startBackupWithoutUpload"}} class="btn">{{i18n 'admin.backups.operations.backup.without_uploads'}}</button> <button {{action "startBackupWithoutUploads"}} class="btn">{{i18n 'admin.backups.operations.backup.without_uploads'}}</button>
<button {{action "cancel"}} class="btn">{{i18n 'no_value'}}</button> <button {{action "cancel"}} class="btn">{{i18n 'no_value'}}</button>
{{/d-modal-body}} {{/d-modal-body}}