diff --git a/app/assets/javascripts/admin/views/admin-backups-logs.js.es6 b/app/assets/javascripts/admin/views/admin-backups-logs.js.es6 index 49d24732e..a7c2af453 100644 --- a/app/assets/javascripts/admin/views/admin-backups-logs.js.es6 +++ b/app/assets/javascripts/admin/views/admin-backups-logs.js.es6 @@ -9,7 +9,7 @@ export default Discourse.View.extend({ this.setProperties({ formattedLogs: "", index: 0 }); }, - _updateFormattedLogs: function() { + _updateFormattedLogs: Discourse.debounce(function() { var logs = this.get("controller.model"); if (logs.length === 0) { this._reset(); // reset the cached logs whenever the model is reset @@ -17,7 +17,7 @@ export default Discourse.View.extend({ // do the log formatting only once for HELLish performance var formattedLogs = this.get("formattedLogs"); for (var i = this.get("index"), length = logs.length; i < length; i++) { - var date = moment(logs[i].get("timestamp")).format("YYYY-MM-DD HH:mm:ss"), + var date = logs[i].get("timestamp"), message = Handlebars.Utils.escapeExpression(logs[i].get("message")); formattedLogs += "[" + date + "] " + message + "\n"; } @@ -26,7 +26,7 @@ export default Discourse.View.extend({ // force rerender this.rerender(); } - }.observes("controller.model.@each"), + }, 150).observes("controller.model.@each"), render: function(buffer) { var formattedLogs = this.get("formattedLogs"); diff --git a/lib/backup_restore/backuper.rb b/lib/backup_restore/backuper.rb index b0bfb6822..3c0ddaf7d 100644 --- a/lib/backup_restore/backuper.rb +++ b/lib/backup_restore/backuper.rb @@ -327,19 +327,20 @@ module BackupRestore end def log(message) + timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S") puts(message) rescue nil - publish_log(message) rescue nil - save_log(message) + publish_log(message, timestamp) rescue nil + save_log(message, timestamp) end - def publish_log(message) + def publish_log(message, timestamp) return unless @publish_to_message_bus - data = { timestamp: Time.now, operation: "backup", message: message } + data = { timestamp: timestamp, operation: "backup", message: message } MessageBus.publish(BackupRestore::LOGS_CHANNEL, data, user_ids: [@user_id]) end - def save_log(message) - @logs << "[#{Time.now}] #{message}" + def save_log(message, timestamp) + @logs << "[#{timestamp}] #{message}" end end diff --git a/lib/backup_restore/restorer.rb b/lib/backup_restore/restorer.rb index a05940633..719339861 100644 --- a/lib/backup_restore/restorer.rb +++ b/lib/backup_restore/restorer.rb @@ -339,19 +339,20 @@ module BackupRestore end def log(message) + timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S") puts(message) rescue nil - publish_log(message) rescue nil - save_log(message) + publish_log(message, timestamp) rescue nil + save_log(message, timestamp) end - def publish_log(message) + def publish_log(message, timestamp) return unless @publish_to_message_bus - data = { timestamp: Time.now, operation: "restore", message: message } + data = { timestamp: timestamp, operation: "restore", message: message } MessageBus.publish(BackupRestore::LOGS_CHANNEL, data, user_ids: [@user_id]) end - def save_log(message) - @logs << "[#{Time.now}] #{message}" + def save_log(message, timestamp) + @logs << "[#{timestamp}] #{message}" end end