FIX: removes uncessary reports loading (#6119)

This commit is contained in:
Joffrey JAFFEUX 2018-07-19 19:30:13 -04:00 committed by GitHub
parent 2bf971c09f
commit 64f0cf425b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 95 additions and 59 deletions

View File

@ -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))

View File

@ -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() {

View File

@ -12,6 +12,7 @@
<div class="charts">
{{admin-report
dataSourceName="signups"
report=signupsReport
showTrend=true
forcedModes="chart"
startDate=startDate
@ -19,6 +20,7 @@
{{admin-report
dataSourceName="topics"
report=topicsReport
showTrend=true
forcedModes="chart"
startDate=startDate
@ -26,6 +28,7 @@
{{admin-report
dataSourceName="posts"
report=postsReport
showTrend=true
forcedModes="chart"
startDate=startDate
@ -33,6 +36,7 @@
{{admin-report
dataSourceName="dau_by_mau"
report=dauByMauReport
showTrend=true
forcedModes="chart"
startDate=startDate
@ -40,6 +44,7 @@
{{admin-report
dataSourceName="daily_engaged_users"
report=dailyEngagedUsersReport
showTrend=true
forcedModes="chart"
startDate=startDate
@ -47,6 +52,7 @@
{{admin-report
dataSourceName="new_contributors"
report=newContributorsReport
showTrend=true
forcedModes="chart"
startDate=startDate

View File

@ -1,6 +1,12 @@
class AdminDashboardNextGeneralData < AdminDashboardNextData
def reports
@reports ||= %w{
signups
topics
posts
dau_by_mau
daily_engaged_users
new_contributors
page_view_total_reqs
visits
time_to_first_response