A platform for community discussion. Free, open, simple.
FIX: removes uncessary reports loading (#6119)
Joffrey JAFFEUX64f0cf425b02
diff --git a/app/assets/javascripts/admin/components/admin-report.js.es6 b/app/assets/javascripts/admin/components/admin-report.js.es6index 1688432962d..f24897b48af 100644--- a/app/assets/javascripts/admin/components/admin-report.js.es6+++ b/app/assets/javascripts/admin/components/admin-report.js.es6@@ -160,6 +160,52 @@ export default Ember.Component.extend({return `admin-report-${currentMode}`;},+ @computed("startDate")+ normalizedStartDate(startDate) {+ return startDate && typeof startDate.isValid === "function"+ ? startDate.format("YYYYMMDD")+ : startDate;+ },++ @computed("endDate")+ normalizedEndDate(endDate) {+ return endDate && typeof endDate.isValid === "function"+ ? endDate.format("YYYYMMDD")+ : endDate;+ },++ @computed(+ "dataSourceName",+ "categoryId",+ "groupId",+ "normalizedStartDate",+ "normalizedEndDate"+ )+ reportKey(dataSourceName, categoryId, groupId, startDate, endDate) {+ if (!dataSourceName || !startDate || !endDate) return null;++ let reportKey = `reports:${dataSourceName}`;++ if (categoryId && categoryId !== "all") {+ reportKey += `:${categoryId}`;+ } else {+ reportKey += `:`;+ }++ reportKey += `:${startDate.replace(/-/g, "")}`;+ reportKey += `:${endDate.replace(/-/g, "")}`;++ if (groupId && groupId !== "all") {+ reportKey += `:${groupId}`;+ } else {+ reportKey += `:`;+ }++ reportKey += `:`;++ return reportKey;+ },+actions: {exportCsv() {exportEntity("report", {@@ -202,39 +248,10 @@ export default Ember.Component.extend({}};- let startDate = this.get("startDate");- let endDate = this.get("endDate");-- startDate =- startDate && typeof startDate.isValid === "function"- ? startDate.format("YYYYMMDD")- : startDate;- endDate =- startDate && typeof endDate.isValid === "function"- ? endDate.format("YYYYMMDD")- : endDate;-- if (!startDate || !endDate) {+ if (!this.get("startDate") || !this.get("endDate")) {report = sort(filteredReports)[0];} else {- let reportKey = `reports:${this.get("dataSourceName")}`;-- if (this.get("categoryId") && this.get("categoryId") !== "all") {- reportKey += `:${this.get("categoryId")}`;- } else {- reportKey += `:`;- }-- reportKey += `:${startDate.replace(/-/g, "")}`;- reportKey += `:${endDate.replace(/-/g, "")}`;-- if (this.get("groupId") && this.get("groupId") !== "all") {- reportKey += `:${this.get("groupId")}`;- } else {- reportKey += `:`;- }-- reportKey += `:`;+ let reportKey = this.get("reportKey");report = sort(filteredReports.filter(r => r.report_key.includes(reportKey))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.es6index 413213b36d9..047c3fae3d9 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@@ -4,6 +4,28 @@ import AdminDashboardNext from "admin/models/admin-dashboard-next";import Report from "admin/models/report";import PeriodComputationMixin from "admin/mixins/period-computation";+const ACTIVITY_METRICS_REPORTS = [+ "page_view_total_reqs",+ "visits",+ "time_to_first_response",+ "likes",+ "flags",+ "user_to_user_private_messages_with_replies"+];++function dynamicReport(reportType) {+ return function() {+ if (this.get("period") !== "monthly") return null;+ return this.get("reports").find(x => x.type === reportType);+ }.property("reports.[]", "period");+}++function staticReport(reportType) {+ return function() {+ return this.get("reports").find(x => x.type === reportType);+ }.property("reports.[]");+}+export default Ember.Controller.extend(PeriodComputationMixin, {isLoading: false,dashboardFetchedAt: null,@@ -25,38 +47,23 @@ export default Ember.Controller.extend(PeriodComputationMixin, {return { table: { total: false, limit: 8 } };},- @computed("reports.[]")- topReferredTopicsReport(reports) {- return reports.find(x => x.type === "top_referred_topics");- },+ signupsReport: dynamicReport("signups"),+ topicsReport: dynamicReport("topics"),+ postsReport: dynamicReport("posts"),+ dauByMauReport: dynamicReport("dau_by_mau"),+ dailyEngagedUsersReport: dynamicReport("daily_engaged_users"),+ newContributorsReport: dynamicReport("new_contributors"),- @computed("reports.[]")- trendingSearchReport(reports) {- return reports.find(x => x.type === "trending_search");- },-- @computed("reports.[]")- usersByTypeReport(reports) {- return reports.find(x => x.type === "users_by_type");- },-- @computed("reports.[]")- usersByTrustLevelReport(reports) {- return reports.find(x => x.type === "users_by_trust_level");- },+ topReferredTopicsReport: staticReport("top_referred_topics"),+ trendingSearchReport: staticReport("trending_search"),+ usersByTypeReport: staticReport("users_by_type"),+ usersByTrustLevelReport: staticReport("users_by_trust_level"),@computed("reports.[]")activityMetricsReports(reports) {- return reports.filter(report => {- return [- "page_view_total_reqs",- "visits",- "time_to_first_response",- "likes",- "flags",- "user_to_user_private_messages_with_replies"- ].includes(report.type);- });+ return reports.filter(report =>+ ACTIVITY_METRICS_REPORTS.includes(report.type)+ );},fetchDashboard() {diff --git a/app/assets/javascripts/admin/templates/dashboard_next_general.hbs b/app/assets/javascripts/admin/templates/dashboard_next_general.hbsindex ea05c6cc9ec..5c022612572 100644--- a/app/assets/javascripts/admin/templates/dashboard_next_general.hbs+++ b/app/assets/javascripts/admin/templates/dashboard_next_general.hbs@@ -12,6 +12,7 @@<div class="charts">{{admin-reportdataSourceName="signups"+ report=signupsReportshowTrend=trueforcedModes="chart"startDate=startDate@@ -19,6 +20,7 @@{{admin-reportdataSourceName="topics"+ report=topicsReportshowTrend=trueforcedModes="chart"startDate=startDate@@ -26,6 +28,7 @@{{admin-reportdataSourceName="posts"+ report=postsReportshowTrend=trueforcedModes="chart"startDate=startDate@@ -33,6 +36,7 @@{{admin-reportdataSourceName="dau_by_mau"+ report=dauByMauReportshowTrend=trueforcedModes="chart"startDate=startDate@@ -40,6 +44,7 @@{{admin-reportdataSourceName="daily_engaged_users"+ report=dailyEngagedUsersReportshowTrend=trueforcedModes="chart"startDate=startDate@@ -47,6 +52,7 @@{{admin-reportdataSourceName="new_contributors"+ report=newContributorsReportshowTrend=trueforcedModes="chart"startDate=startDatediff --git a/app/models/admin_dashboard_next_general_data.rb b/app/models/admin_dashboard_next_general_data.rbindex 36c5d90cbb2..84d1a1a49b2 100644--- a/app/models/admin_dashboard_next_general_data.rb+++ b/app/models/admin_dashboard_next_general_data.rb@@ -1,6 +1,12 @@class AdminDashboardNextGeneralData < AdminDashboardNextDatadef reports@reports ||= %w{+ signups+ topics+ posts+ dau_by_mau+ daily_engaged_users+ new_contributorspage_view_total_reqsvisitstime_to_first_response