FIX: The `LogsNotice` service was never unsubscribing from the mbus

FIX: The LogsNotice service was never unsubscribing from the mbus

Whenever we subscribe to something there should be an equivalent unsubscribe and this implements it for LogsNotice.

In the future we should make this closer to what Ember expects a Service to be, but at least it’s properly cleaning up after itself now.

diff --git a/app/assets/javascripts/discourse/app/initializers/logs-notice.js b/app/assets/javascripts/discourse/app/initializers/logs-notice.js
index 08867d1..e4e69ad 100644
--- a/app/assets/javascripts/discourse/app/initializers/logs-notice.js
+++ b/app/assets/javascripts/discourse/app/initializers/logs-notice.js
@@ -5,7 +5,7 @@ export default {
   name: "logs-notice",
   after: "message-bus",
 
-  initialize: function (container) {
+  initialize(container) {
     const siteSettings = container.lookup("site-settings:main");
     const messageBus = container.lookup("message-bus:main");
     const keyValueStore = container.lookup("key-value-store:main");
@@ -21,4 +21,8 @@ export default {
       },
     });
   },
+
+  teardown() {
+    LogsNotice.current().destroy();
+  },
 };
diff --git a/app/assets/javascripts/discourse/app/services/logs-notice.js b/app/assets/javascripts/discourse/app/services/logs-notice.js
index 6c77e7c..0a92c3f 100644
--- a/app/assets/javascripts/discourse/app/services/logs-notice.js
+++ b/app/assets/javascripts/discourse/app/services/logs-notice.js
@@ -1,7 +1,4 @@
-import discourseComputed, {
-  observes,
-  on,
-} from "discourse-common/utils/decorators";
+import discourseComputed, { observes } from "discourse-common/utils/decorators";
 import EmberObject from "@ember/object";
 import I18n from "I18n";
 import { autoUpdatingRelativeAge } from "discourse/lib/formatter";
@@ -11,11 +8,14 @@ import { isEmpty } from "@ember/utils";
 
 const LOGS_NOTICE_KEY = "logs-notice-text";
 
-const LogsNotice = EmberObject.extend({
+const CHANNEL = "/logs_error_rate_exceeded";
+
+export default EmberObject.extend({
   text: "",
 
-  @on("init")
-  _setup() {
+  init() {
+    this._super();
+
     if (!this.isActivated) {
       return;
     }
@@ -25,7 +25,7 @@ const LogsNotice = EmberObject.extend({
       this.set("text", text);
     }
 
-    this.messageBus.subscribe("/logs_error_rate_exceeded", (data) => {
+    this.messageBus.subscribe(CHANNEL, (data) => {
       const duration = data.duration;
       const rate = data.rate;
       let siteSettingLimit = 0;
@@ -53,6 +53,11 @@ const LogsNotice = EmberObject.extend({
     });
   },
 
+  willDestroy() {
+    this._super();
+    this.messageBus.unsubscribe(CHANNEL);
+  },
+
   @discourseComputed("text")
   isEmpty(text) {
     return isEmpty(text);
@@ -86,5 +91,3 @@ const LogsNotice = EmberObject.extend({
     return errorsPerHour > 0 || errorsPerMinute > 0;
   },
 });
-
-export default LogsNotice;

GitHub sha: 14b76dece6126cd0a04a6390d39517a383c72bf9

This commit appears in #14150 which was approved by markvanlan. It was merged by eviltrout.