Merge pull request #6131 from jjaffeux/lazy-load-reports

FIX: lazy load more reports in dashboard
This commit is contained in:
Guo Xiang Tan 2018-07-21 17:24:17 +08:00 committed by GitHub
commit 5c1bd38d84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 36 additions and 158 deletions

View File

@ -13,13 +13,6 @@ const ACTIVITY_METRICS_REPORTS = [
"user_to_user_private_messages_with_replies" "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) { function staticReport(reportType) {
return function() { return function() {
return this.get("reports").find(x => x.type === reportType); return this.get("reports").find(x => x.type === reportType);
@ -47,15 +40,6 @@ export default Ember.Controller.extend(PeriodComputationMixin, {
return { table: { total: false, limit: 8 } }; return { table: { total: false, limit: 8 } };
}, },
signupsReport: dynamicReport("signups"),
topicsReport: dynamicReport("topics"),
postsReport: dynamicReport("posts"),
dauByMauReport: dynamicReport("dau_by_mau"),
dailyEngagedUsersReport: dynamicReport("daily_engaged_users"),
newContributorsReport: dynamicReport("new_contributors"),
topReferredTopicsReport: staticReport("top_referred_topics"),
trendingSearchReport: staticReport("trending_search"),
usersByTypeReport: staticReport("users_by_type"), usersByTypeReport: staticReport("users_by_type"),
usersByTrustLevelReport: staticReport("users_by_trust_level"), usersByTrustLevelReport: staticReport("users_by_trust_level"),

View File

@ -1,11 +1,7 @@
import computed from "ember-addons/ember-computed-decorators"; import computed from "ember-addons/ember-computed-decorators";
import Report from "admin/models/report";
import AdminDashboardNext from "admin/models/admin-dashboard-next";
import PeriodComputationMixin from "admin/mixins/period-computation"; import PeriodComputationMixin from "admin/mixins/period-computation";
export default Ember.Controller.extend(PeriodComputationMixin, { export default Ember.Controller.extend(PeriodComputationMixin, {
isLoading: false,
dashboardFetchedAt: null,
exceptionController: Ember.inject.controller("exception"), exceptionController: Ember.inject.controller("exception"),
@computed @computed
@ -18,46 +14,6 @@ export default Ember.Controller.extend(PeriodComputationMixin, {
}; };
}, },
@computed("reports.[]")
flagsStatusReport(reports) {
return reports.find(x => x.type === "flags_status");
},
@computed("reports.[]")
postEditsReport(reports) {
return reports.find(x => x.type === "post_edits");
},
fetchDashboard() {
if (this.get("isLoading")) return;
if (
!this.get("dashboardFetchedAt") ||
moment()
.subtract(30, "minutes")
.toDate() > this.get("dashboardFetchedAt")
) {
this.set("isLoading", true);
AdminDashboardNext.fetchModeration()
.then(model => {
const reports = model.reports.map(x => Report.create(x));
this.setProperties({
dashboardFetchedAt: new Date(),
model,
reports
});
})
.catch(e => {
this.get("exceptionController").set("thrown", e.jqXHR);
this.replaceRoute("exception");
})
.finally(() => {
this.set("isLoading", false);
});
}
},
_reportsForPeriodURL(period) { _reportsForPeriodURL(period) {
return Discourse.getURL(`/admin/dashboard/moderation?period=${period}`); return Discourse.getURL(`/admin/dashboard/moderation?period=${period}`);
} }

View File

@ -13,17 +13,6 @@ AdminDashboardNext.reopenClass({
}); });
}, },
fetchModeration() {
return ajax("/admin/dashboard/moderation.json").then(json => {
const model = AdminDashboardNext.create();
model.setProperties({
reports: json.reports,
loaded: true
});
return model;
});
},
fetchGeneral() { fetchGeneral() {
return ajax("/admin/dashboard/general.json").then(json => { return ajax("/admin/dashboard/general.json").then(json => {
const model = AdminDashboardNext.create(); const model = AdminDashboardNext.create();

View File

@ -1,5 +0,0 @@
export default Discourse.Route.extend({
activate() {
this.controllerFor("admin-dashboard-next-moderation").fetchDashboard();
}
});

View File

@ -16,7 +16,6 @@
<div class="charts"> <div class="charts">
{{admin-report {{admin-report
dataSourceName="signups" dataSourceName="signups"
report=signupsReport
showTrend=true showTrend=true
forcedModes="chart" forcedModes="chart"
startDate=startDate startDate=startDate
@ -24,7 +23,6 @@
{{admin-report {{admin-report
dataSourceName="topics" dataSourceName="topics"
report=topicsReport
showTrend=true showTrend=true
forcedModes="chart" forcedModes="chart"
startDate=startDate startDate=startDate
@ -32,7 +30,6 @@
{{admin-report {{admin-report
dataSourceName="posts" dataSourceName="posts"
report=postsReport
showTrend=true showTrend=true
forcedModes="chart" forcedModes="chart"
startDate=startDate startDate=startDate
@ -40,7 +37,6 @@
{{admin-report {{admin-report
dataSourceName="dau_by_mau" dataSourceName="dau_by_mau"
report=dauByMauReport
showTrend=true showTrend=true
forcedModes="chart" forcedModes="chart"
startDate=startDate startDate=startDate
@ -48,7 +44,6 @@
{{admin-report {{admin-report
dataSourceName="daily_engaged_users" dataSourceName="daily_engaged_users"
report=dailyEngagedUsersReport
showTrend=true showTrend=true
forcedModes="chart" forcedModes="chart"
startDate=startDate startDate=startDate
@ -56,7 +51,6 @@
{{admin-report {{admin-report
dataSourceName="new_contributors" dataSourceName="new_contributors"
report=newContributorsReport
showTrend=true showTrend=true
forcedModes="chart" forcedModes="chart"
startDate=startDate startDate=startDate
@ -171,13 +165,11 @@
</div> </div>
<div class="section-column"> <div class="section-column">
{{admin-report {{admin-report dataSourceName="top_referred_topics" reportOptions=topReferredTopicsTopions}}
report=topReferredTopicsReport
reportOptions=topReferredTopicsTopions}}
{{admin-report {{admin-report
dataSourceName="trending_search"
reportOptions=trendingSearchOptions reportOptions=trendingSearchOptions
report=trendingSearchReport
isEnabled=logSearchQueriesEnabled isEnabled=logSearchQueriesEnabled
disabledLabel="admin.dashboard.reports.trending_search.disabled" disabledLabel="admin.dashboard.reports.trending_search.disabled"
startDate=startDate startDate=startDate

View File

@ -1,4 +1,3 @@
{{#conditional-loading-spinner condition=isLoading}}
<div class="sections"> <div class="sections">
{{plugin-outlet name="admin-dashboard-moderation-top"}} {{plugin-outlet name="admin-dashboard-moderation-top"}}
@ -27,18 +26,16 @@
<div class="main-section"> <div class="main-section">
{{admin-report {{admin-report
report=flagsStatusReport dataSourceName="flags_status"
startDate=lastWeek startDate=lastWeek
reportOptions=flagsStatusOptions reportOptions=flagsStatusOptions
endDate=endDate}} endDate=endDate}}
{{admin-report {{admin-report
report=postEditsReport dataSourceName="post_edits"
startDate=lastWeek startDate=lastWeek
endDate=endDate}} endDate=endDate}}
{{plugin-outlet name="admin-dashboard-moderation-bottom"}} {{plugin-outlet name="admin-dashboard-moderation-bottom"}}
</div> </div>
</div> </div>
{{/conditional-loading-spinner}}

View File

@ -11,10 +11,6 @@ class Admin::DashboardNextController < Admin::AdminController
render json: data render json: data
end end
def moderation
render json: AdminDashboardNextModerationData.fetch_cached_stats
end
def general def general
data = AdminDashboardNextGeneralData.fetch_cached_stats data = AdminDashboardNextGeneralData.fetch_cached_stats

View File

@ -1,7 +1,6 @@
require_dependency 'admin_dashboard_data' require_dependency 'admin_dashboard_data'
require_dependency 'admin_dashboard_next_index_data' require_dependency 'admin_dashboard_next_index_data'
require_dependency 'admin_dashboard_next_general_data' require_dependency 'admin_dashboard_next_general_data'
require_dependency 'admin_dashboard_next_moderation_data'
require_dependency 'group' require_dependency 'group'
require_dependency 'group_message' require_dependency 'group_message'
@ -18,9 +17,7 @@ module Jobs
end end
# TODO: decide if we want to keep caching this every 30 minutes # TODO: decide if we want to keep caching this every 30 minutes
AdminDashboardNextIndexData.refresh_stats
AdminDashboardNextGeneralData.refresh_stats AdminDashboardNextGeneralData.refresh_stats
AdminDashboardNextModerationData.refresh_stats
AdminDashboardData.refresh_stats AdminDashboardData.refresh_stats
end end
end end

View File

@ -1,22 +1,14 @@
class AdminDashboardNextGeneralData < AdminDashboardNextData class AdminDashboardNextGeneralData < AdminDashboardNextData
def reports def reports
@reports ||= %w{ @reports ||= %w{
signups
topics
posts
dau_by_mau
daily_engaged_users
new_contributors
page_view_total_reqs page_view_total_reqs
visits visits
time_to_first_response time_to_first_response
likes likes
flags flags
user_to_user_private_messages_with_replies user_to_user_private_messages_with_replies
top_referred_topics
users_by_type users_by_type
users_by_trust_level users_by_trust_level
trending_search
} }
end end

View File

@ -1,19 +0,0 @@
class AdminDashboardNextModerationData < AdminDashboardNextData
def reports
@reports ||= %w{
flags_status
post_edits
}
end
def get_json
{
reports: self.class.reports(reports),
updated_at: Time.zone.now.as_json
}
end
def self.stats_cache_key
'moderation-dashboard-data'
end
end

View File

@ -238,7 +238,6 @@ Discourse::Application.routes.draw do
get "dashboard-next" => "dashboard_next#index" get "dashboard-next" => "dashboard_next#index"
get "dashboard-old" => "dashboard#index" get "dashboard-old" => "dashboard#index"
get "dashboard/moderation" => "dashboard_next#moderation"
get "dashboard/general" => "dashboard_next#general" get "dashboard/general" => "dashboard_next#general"
resources :dashboard, only: [:index] do resources :dashboard, only: [:index] do