FEATURE: Improve backup stats on admin dashboard

FEATURE: Improve backup stats on admin dashboard
  • Dashboard doesn’t timeout anymore when Amazon S3 is used for backups
  • Storage stats are now a proper report with the same caching rules
  • Changing the backup_location, s3_backup_bucket or creating and deleting backups removes the report from the cache
  • It shows the number of backups and the backup location
  • It shows the used space for the correct backup location instead of always showing used space on local storage
  • It shows the date of the last backup as relative date
diff --git a/app/assets/javascripts/admin/components/admin-report-storage-stats.js.es6 b/app/assets/javascripts/admin/components/admin-report-storage-stats.js.es6
new file mode 100644
index 0000000..c4bf831
--- /dev/null
+++ b/app/assets/javascripts/admin/components/admin-report-storage-stats.js.es6
@@ -0,0 +1,40 @@
+import { setting } from "discourse/lib/computed";
+import computed from "ember-addons/ember-computed-decorators";
+
+export default Ember.Component.extend({
+  classNames: ["admin-report-storage-stats"],
+
+  backupLocation: setting("backup_location"),
+  backupStats: Ember.computed.alias("model.data.backups"),
+  uploadStats: Ember.computed.alias("model.data.uploads"),
+
+  @computed("backupStats")
+  showBackupStats(stats) {
+    return stats && this.currentUser.admin;
+  },
+
+  @computed("backupLocation")
+  backupLocationName(backupLocation) {
+    return I18n.t(`admin.backups.location.${backupLocation}`);
+  },
+
+  @computed("backupStats.used_bytes")
+  usedBackupSpace(bytes) {
+    return I18n.toHumanSize(bytes);
+  },
+
+  @computed("backupStats.free_bytes")
+  freeBackupSpace(bytes) {
+    return I18n.toHumanSize(bytes);
+  },
+
+  @computed("uploadStats.used_bytes")
+  usedUploadSpace(bytes) {
+    return I18n.toHumanSize(bytes);
+  },
+
+  @computed("uploadStats.free_bytes")
+  freeUploadSpace(bytes) {
+    return I18n.toHumanSize(bytes);
+  }
+});
diff --git a/app/assets/javascripts/admin/controllers/admin-dashboard-next-general.js.es6 b/app/assets/javascripts/admin/controllers/admin-dashboard-next-general.js.es6
index f229ef7..c084368 100644
--- a/app/assets/javascripts/admin/controllers/admin-dashboard-next-general.js.es6
+++ b/app/assets/javascripts/admin/controllers/admin-dashboard-next-general.js.es6
@@ -16,12 +16,7 @@ export default Ember.Controller.extend(PeriodComputationMixin, {
   isLoading: false,
   dashboardFetchedAt: null,
   exceptionController: Ember.inject.controller("exception"),
-  diskSpace: Ember.computed.alias("model.attributes.disk_space"),
   logSearchQueriesEnabled: setting("log_search_queries"),
-  lastBackupTakenAt: Ember.computed.alias(
-    "model.attributes.last_backup_taken_at"
-  ),
-  shouldDisplayDurability: Ember.computed.and("diskSpace"),
   basePath: Discourse.BaseUri,
 
   @computed
@@ -87,6 +82,7 @@ export default Ember.Controller.extend(PeriodComputationMixin, {
 
   usersByTypeReport: staticReport("users_by_type"),
   usersByTrustLevelReport: staticReport("users_by_trust_level"),
+  storageReport: staticReport("storage_report"),
 
   fetchDashboard() {
     if (this.get("isLoading")) return;
@@ -129,13 +125,6 @@ export default Ember.Controller.extend(PeriodComputationMixin, {
       .format("LLL");
   },
 
-  @computed("lastBackupTakenAt")
-  backupTimestamp(lastBackupTakenAt) {
-    return moment(lastBackupTakenAt)
-      .tz(moment.tz.guess())
-      .format("LLL");
-  },
-
   _reportsForPeriodURL(period) {
     return Discourse.getURL(`/admin?period=${period}`);
   }
diff --git a/app/assets/javascripts/admin/controllers/admin-dashboard.js.es6 b/app/assets/javascripts/admin/controllers/admin-dashboard.js.es6
index 9b545fc..b0e3047 100644
--- a/app/assets/javascripts/admin/controllers/admin-dashboard.js.es6
+++ b/app/assets/javascripts/admin/controllers/admin-dashboard.js.es6
@@ -4,7 +4,6 @@ import AdminUser from "admin/models/admin-user";
 import computed from "ember-addons/ember-computed-decorators";
 
 const ATTRIBUTES = [
-  "disk_space",
   "admins",
   "moderators",
   "silenced",
diff --git a/app/assets/javascripts/admin/models/admin-dashboard-next.js.es6 b/app/assets/javascripts/admin/models/admin-dashboard-next.js.es6
index 6898f81..f4f3eec 100644
--- a/app/assets/javascripts/admin/models/admin-dashboard-next.js.es6
+++ b/app/assets/javascripts/admin/models/admin-dashboard-next.js.es6
@@ -1,6 +1,6 @@
 import { ajax } from "discourse/lib/ajax";
 
-const GENERAL_ATTRIBUTES = ["disk_space", "updated_at", "last_backup_taken_at"];
+const GENERAL_ATTRIBUTES = ["updated_at"];
 
 const AdminDashboardNext = Discourse.Model.extend({});
 
diff --git a/app/assets/javascripts/admin/templates/components/admin-report-storage-stats.hbs b/app/assets/javascripts/admin/templates/components/admin-report-storage-stats.hbs
new file mode 100644
index 0000000..054b91d
--- /dev/null
+++ b/app/assets/javascripts/admin/templates/components/admin-report-storage-stats.hbs
@@ -0,0 +1,33 @@
+{{#if showBackupStats}}
+  <div class="backups">
+    <h3 class="storage-stats-title">
+      <a href="{{get-url '/admin/backups'}}">{{d-icon "archive"}} {{i18n "admin.dashboard.backups"}}</a>
+    </h3>
+    <p>
+      {{#if backupStats.free_bytes}}
+        {{i18n "admin.dashboard.space_used_and_free" usedSize=usedBackupSpace freeSize=freeBackupSpace}}
+      {{else}}
+        {{i18n "admin.dashboard.space_used" usedSize=usedBackupSpace}}
+      {{/if}}
+
+      <br>
+      {{i18n "admin.dashboard.backup_count" count=backupStats.count location=backupLocationName}}
+
+      {{#if backupStats.last_backup_taken_at}}
+        <br>
+        {{{i18n "admin.dashboard.lastest_backup" date=(format-date backupStats.last_backup_taken_at leaveAgo="true")}}}
+      {{/if}}
+    </p>
+  </div>
+{{/if}}
+
+<div class="uploads">
+  <h3 class="storage-stats-title">{{d-icon "upload"}} {{i18n "admin.dashboard.uploads"}}</h3>
+  <p>
+    {{#if uploadStats.free_bytes}}
+      {{i18n "admin.dashboard.space_used_and_free" usedSize=usedUploadSpace freeSize=freeUploadSpace}}
+    {{else}}
+      {{i18n "admin.dashboard.space_used" usedSize=usedUploadSpace}}
+    {{/if}}
+  </p>
+</div>
diff --git a/app/assets/javascripts/admin/templates/dashboard_next_general.hbs b/app/assets/javascripts/admin/templates/dashboard_next_general.hbs
index 75c24cf..5842f31 100644
--- a/app/assets/javascripts/admin/templates/dashboard_next_general.hbs
+++ b/app/assets/javascripts/admin/templates/dashboard_next_general.hbs
@@ -103,51 +103,26 @@
         {{/conditional-loading-section}}
       </div>
 
-      {{#conditional-loading-section isLoading=isLoading title=(i18n "admin.dashboard.backups")}}
-        <div class="misc">
-
-          {{#if shouldDisplayDurability}}
-            <div class="durability">
-              {{#if currentUser.admin}}
-                <div class="backups">
-                  <h3 class="durability-title">
-                    <a href="{{get-url '/admin/backups'}}">{{d-icon "archive"}} {{i18n "admin.dashboard.backups"}}</a>
-                  </h3>
-                  <p>
-                    {{diskSpace.backups_used}} ({{i18n "admin.dashboard.space_free" size=diskSpace.backups_free}})
-
-                    {{#if lastBackupTakenAt}}
-                      <br />
-                      {{{i18n "admin.dashboard.lastest_backup" date=backupTimestamp}}}
-                    {{/if}}
-                  </p>
-                </div>
-              {{/if}}
-
-              <div class="uploads">
-                <h3 class="durability-title">{{d-icon "upload"}} {{i18n "admin.dashboard.uploads"}}</h3>
-                <p>
-                  {{diskSpace.uploads_used}} ({{i18n "admin.dashboard.space_free" size=diskSpace.uploads_free}})
-                </p>
-              </div>
-            </div>
-          {{/if}}
-
-          <div class="last-dashboard-update">
-            <div>
+      <div class="misc">
+        {{admin-report
+          forcedModes="storage-stats"
+          dataSourceName="storage_stats"
+          showHeader=false}}
+
+        <div class="last-dashboard-update">
+          <div>
             <h4>{{i18n "admin.dashboard.last_updated"}} </h4>
             <p>{{updatedTimestamp}}</p>
-               <a rel="noopener" target="_blank" href="https://meta.discourse.org/tags/release-notes" class="btn btn-default">
-                 {{i18n "admin.dashboard.whats_new_in_discourse"}}
-                </a>
-            </div>
+            <a rel="noopener" target="_blank" href="https://meta.discourse.org/tags/release-notes" class="btn btn-default">

[... diff too long, it was truncated ...]

GitHub
sha: 1a8ca68e

2 Likes

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/dashboard-fails-due-to-s3-timeout/103687/9

:heart: