mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 21:10:17 +08:00
Merge pull request #6131 from jjaffeux/lazy-load-reports
FIX: lazy load more reports in dashboard
This commit is contained in:
commit
5c1bd38d84
|
@ -13,13 +13,6 @@ const ACTIVITY_METRICS_REPORTS = [
|
|||
"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);
|
||||
|
@ -47,15 +40,6 @@ export default Ember.Controller.extend(PeriodComputationMixin, {
|
|||
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"),
|
||||
usersByTrustLevelReport: staticReport("users_by_trust_level"),
|
||||
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
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";
|
||||
|
||||
export default Ember.Controller.extend(PeriodComputationMixin, {
|
||||
isLoading: false,
|
||||
dashboardFetchedAt: null,
|
||||
exceptionController: Ember.inject.controller("exception"),
|
||||
|
||||
@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) {
|
||||
return Discourse.getURL(`/admin/dashboard/moderation?period=${period}`);
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
return ajax("/admin/dashboard/general.json").then(json => {
|
||||
const model = AdminDashboardNext.create();
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
export default Discourse.Route.extend({
|
||||
activate() {
|
||||
this.controllerFor("admin-dashboard-next-moderation").fetchDashboard();
|
||||
}
|
||||
});
|
|
@ -16,7 +16,6 @@
|
|||
<div class="charts">
|
||||
{{admin-report
|
||||
dataSourceName="signups"
|
||||
report=signupsReport
|
||||
showTrend=true
|
||||
forcedModes="chart"
|
||||
startDate=startDate
|
||||
|
@ -24,7 +23,6 @@
|
|||
|
||||
{{admin-report
|
||||
dataSourceName="topics"
|
||||
report=topicsReport
|
||||
showTrend=true
|
||||
forcedModes="chart"
|
||||
startDate=startDate
|
||||
|
@ -32,7 +30,6 @@
|
|||
|
||||
{{admin-report
|
||||
dataSourceName="posts"
|
||||
report=postsReport
|
||||
showTrend=true
|
||||
forcedModes="chart"
|
||||
startDate=startDate
|
||||
|
@ -40,7 +37,6 @@
|
|||
|
||||
{{admin-report
|
||||
dataSourceName="dau_by_mau"
|
||||
report=dauByMauReport
|
||||
showTrend=true
|
||||
forcedModes="chart"
|
||||
startDate=startDate
|
||||
|
@ -48,7 +44,6 @@
|
|||
|
||||
{{admin-report
|
||||
dataSourceName="daily_engaged_users"
|
||||
report=dailyEngagedUsersReport
|
||||
showTrend=true
|
||||
forcedModes="chart"
|
||||
startDate=startDate
|
||||
|
@ -56,7 +51,6 @@
|
|||
|
||||
{{admin-report
|
||||
dataSourceName="new_contributors"
|
||||
report=newContributorsReport
|
||||
showTrend=true
|
||||
forcedModes="chart"
|
||||
startDate=startDate
|
||||
|
@ -171,13 +165,11 @@
|
|||
</div>
|
||||
|
||||
<div class="section-column">
|
||||
{{admin-report
|
||||
report=topReferredTopicsReport
|
||||
reportOptions=topReferredTopicsTopions}}
|
||||
{{admin-report dataSourceName="top_referred_topics" reportOptions=topReferredTopicsTopions}}
|
||||
|
||||
{{admin-report
|
||||
dataSourceName="trending_search"
|
||||
reportOptions=trendingSearchOptions
|
||||
report=trendingSearchReport
|
||||
isEnabled=logSearchQueriesEnabled
|
||||
disabledLabel="admin.dashboard.reports.trending_search.disabled"
|
||||
startDate=startDate
|
||||
|
|
|
@ -1,44 +1,41 @@
|
|||
{{#conditional-loading-spinner condition=isLoading}}
|
||||
<div class="sections">
|
||||
{{plugin-outlet name="admin-dashboard-moderation-top"}}
|
||||
<div class="sections">
|
||||
{{plugin-outlet name="admin-dashboard-moderation-top"}}
|
||||
|
||||
<div class="moderators-activity section">
|
||||
<div class="section-title">
|
||||
<h2>
|
||||
<a href="/admin/reports/moderators_activity">
|
||||
{{i18n "admin.dashboard.moderators_activity"}}
|
||||
</a>
|
||||
</h2>
|
||||
{{period-chooser
|
||||
period=period
|
||||
action="changePeriod"
|
||||
content=availablePeriods
|
||||
fullDay=true}}
|
||||
</div>
|
||||
|
||||
<div class="section-body">
|
||||
{{admin-report
|
||||
startDate=startDate
|
||||
endDate=endDate
|
||||
showHeader=false
|
||||
dataSourceName="moderators_activity"}}
|
||||
</div>
|
||||
<div class="moderators-activity section">
|
||||
<div class="section-title">
|
||||
<h2>
|
||||
<a href="/admin/reports/moderators_activity">
|
||||
{{i18n "admin.dashboard.moderators_activity"}}
|
||||
</a>
|
||||
</h2>
|
||||
{{period-chooser
|
||||
period=period
|
||||
action="changePeriod"
|
||||
content=availablePeriods
|
||||
fullDay=true}}
|
||||
</div>
|
||||
|
||||
<div class="main-section">
|
||||
<div class="section-body">
|
||||
{{admin-report
|
||||
report=flagsStatusReport
|
||||
startDate=lastWeek
|
||||
reportOptions=flagsStatusOptions
|
||||
endDate=endDate}}
|
||||
|
||||
{{admin-report
|
||||
report=postEditsReport
|
||||
startDate=lastWeek
|
||||
endDate=endDate}}
|
||||
|
||||
{{plugin-outlet name="admin-dashboard-moderation-bottom"}}
|
||||
startDate=startDate
|
||||
endDate=endDate
|
||||
showHeader=false
|
||||
dataSourceName="moderators_activity"}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{/conditional-loading-spinner}}
|
||||
<div class="main-section">
|
||||
{{admin-report
|
||||
dataSourceName="flags_status"
|
||||
startDate=lastWeek
|
||||
reportOptions=flagsStatusOptions
|
||||
endDate=endDate}}
|
||||
|
||||
{{admin-report
|
||||
dataSourceName="post_edits"
|
||||
startDate=lastWeek
|
||||
endDate=endDate}}
|
||||
|
||||
{{plugin-outlet name="admin-dashboard-moderation-bottom"}}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -11,10 +11,6 @@ class Admin::DashboardNextController < Admin::AdminController
|
|||
render json: data
|
||||
end
|
||||
|
||||
def moderation
|
||||
render json: AdminDashboardNextModerationData.fetch_cached_stats
|
||||
end
|
||||
|
||||
def general
|
||||
data = AdminDashboardNextGeneralData.fetch_cached_stats
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
require_dependency 'admin_dashboard_data'
|
||||
require_dependency 'admin_dashboard_next_index_data'
|
||||
require_dependency 'admin_dashboard_next_general_data'
|
||||
require_dependency 'admin_dashboard_next_moderation_data'
|
||||
require_dependency 'group'
|
||||
require_dependency 'group_message'
|
||||
|
||||
|
@ -18,9 +17,7 @@ module Jobs
|
|||
end
|
||||
|
||||
# TODO: decide if we want to keep caching this every 30 minutes
|
||||
AdminDashboardNextIndexData.refresh_stats
|
||||
AdminDashboardNextGeneralData.refresh_stats
|
||||
AdminDashboardNextModerationData.refresh_stats
|
||||
AdminDashboardData.refresh_stats
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,22 +1,14 @@
|
|||
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
|
||||
likes
|
||||
flags
|
||||
user_to_user_private_messages_with_replies
|
||||
top_referred_topics
|
||||
users_by_type
|
||||
users_by_trust_level
|
||||
trending_search
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -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
|
|
@ -238,7 +238,6 @@ Discourse::Application.routes.draw do
|
|||
|
||||
get "dashboard-next" => "dashboard_next#index"
|
||||
get "dashboard-old" => "dashboard#index"
|
||||
get "dashboard/moderation" => "dashboard_next#moderation"
|
||||
get "dashboard/general" => "dashboard_next#general"
|
||||
|
||||
resources :dashboard, only: [:index] do
|
||||
|
|
Loading…
Reference in New Issue
Block a user