From c9a007d5fb05ee42fa193a8937daf4562bab0f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 9 Feb 2015 16:53:28 +0100 Subject: [PATCH] FIX: backup logs on Firefox FIX: debounce backup logs in order to prevent Firefox crash FIX: 'Invalid date' in backup logs in Firefox --- .../admin/views/admin-backups-logs.js.es6 | 6 +++--- lib/backup_restore/backuper.rb | 13 +++++++------ lib/backup_restore/restorer.rb | 13 +++++++------ 3 files changed, 17 insertions(+), 15 deletions(-) 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 49d24732e2f..a7c2af453b5 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 b0bfb6822d9..3c0ddaf7d8f 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 a0594063373..71933986189 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