Add: 管理画面で特に負荷の大きい処理を無効にする環境変数 (#633)
This commit is contained in:
parent
0ed58512a1
commit
0a3007a9b0
7 changed files with 41 additions and 5 deletions
8
app/helpers/high_load_helper.rb
Normal file
8
app/helpers/high_load_helper.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module HighLoadHelper
|
||||||
|
def allow_high_load?
|
||||||
|
ENV.fetch('ALLOW_HIGH_LOAD', 'true') == 'true'
|
||||||
|
end
|
||||||
|
module_function :allow_high_load?
|
||||||
|
end
|
|
@ -1,7 +1,7 @@
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { PureComponent } from 'react';
|
import { PureComponent } from 'react';
|
||||||
|
|
||||||
import { FormattedNumber } from 'react-intl';
|
import { FormattedNumber, FormattedMessage } from 'react-intl';
|
||||||
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ export default class Counter extends PureComponent {
|
||||||
state = {
|
state = {
|
||||||
loading: true,
|
loading: true,
|
||||||
data: null,
|
data: null,
|
||||||
|
empty: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
|
@ -52,6 +53,7 @@ export default class Counter extends PureComponent {
|
||||||
this.setState({
|
this.setState({
|
||||||
loading: false,
|
loading: false,
|
||||||
data: res.data,
|
data: res.data,
|
||||||
|
empty: res.data.length === 0,
|
||||||
});
|
});
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
@ -60,7 +62,7 @@ export default class Counter extends PureComponent {
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { label, href, target } = this.props;
|
const { label, href, target } = this.props;
|
||||||
const { loading, data } = this.state;
|
const { loading, data, empty } = this.state;
|
||||||
|
|
||||||
let content;
|
let content;
|
||||||
|
|
||||||
|
@ -71,6 +73,12 @@ export default class Counter extends PureComponent {
|
||||||
<span className='sparkline__value__change'><Skeleton width={43} /></span>
|
<span className='sparkline__value__change'><Skeleton width={43} /></span>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
} else if (empty) {
|
||||||
|
content = (
|
||||||
|
<span className='sparkline__value__change'>
|
||||||
|
<FormattedMessage id='admin.dimenssions.disabled_key' defaultMessage='This information is invalid.' />
|
||||||
|
</span>
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
const measure = data[0];
|
const measure = data[0];
|
||||||
const percentChange = measure.previous_total && percIncrease(measure.previous_total * 1, measure.total * 1);
|
const percentChange = measure.previous_total && percIncrease(measure.previous_total * 1, measure.total * 1);
|
||||||
|
@ -94,7 +102,7 @@ export default class Counter extends PureComponent {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='sparkline__graph'>
|
<div className='sparkline__graph'>
|
||||||
{!loading && (
|
{!loading && !empty && (
|
||||||
<Sparklines width={259} height={55} data={data[0].data.map(x => x.value * 1)}>
|
<Sparklines width={259} height={55} data={data[0].data.map(x => x.value * 1)}>
|
||||||
<SparklinesCurve />
|
<SparklinesCurve />
|
||||||
</Sparklines>
|
</Sparklines>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { PureComponent } from 'react';
|
import { PureComponent } from 'react';
|
||||||
|
|
||||||
import { FormattedNumber } from 'react-intl';
|
import { FormattedNumber, FormattedMessage } from 'react-intl';
|
||||||
|
|
||||||
import api from 'mastodon/api';
|
import api from 'mastodon/api';
|
||||||
import { Skeleton } from 'mastodon/components/skeleton';
|
import { Skeleton } from 'mastodon/components/skeleton';
|
||||||
|
@ -21,6 +21,7 @@ export default class Dimension extends PureComponent {
|
||||||
state = {
|
state = {
|
||||||
loading: true,
|
loading: true,
|
||||||
data: null,
|
data: null,
|
||||||
|
empty: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
|
@ -30,6 +31,7 @@ export default class Dimension extends PureComponent {
|
||||||
this.setState({
|
this.setState({
|
||||||
loading: false,
|
loading: false,
|
||||||
data: res.data,
|
data: res.data,
|
||||||
|
empty: res.data.length === 0,
|
||||||
});
|
});
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
@ -38,7 +40,7 @@ export default class Dimension extends PureComponent {
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { label, limit } = this.props;
|
const { label, limit } = this.props;
|
||||||
const { loading, data } = this.state;
|
const { loading, data, empty } = this.state;
|
||||||
|
|
||||||
let content;
|
let content;
|
||||||
|
|
||||||
|
@ -60,6 +62,18 @@ export default class Dimension extends PureComponent {
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
);
|
);
|
||||||
|
} else if (empty) {
|
||||||
|
content = (
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<tr className='dimension__item'>
|
||||||
|
<td className='dimension__item__value' colSpan={2}>
|
||||||
|
<FormattedMessage id='admin.dimenssions.disabled_key' defaultMessage='This information is invalid.' />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
const sum = data[0].data.reduce((sum, cur) => sum + (cur.value * 1), 0);
|
const sum = data[0].data.reduce((sum, cur) => sum + (cur.value * 1), 0);
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,7 @@
|
||||||
"admin.dashboard.retention.average": "Average",
|
"admin.dashboard.retention.average": "Average",
|
||||||
"admin.dashboard.retention.cohort": "Sign-up month",
|
"admin.dashboard.retention.cohort": "Sign-up month",
|
||||||
"admin.dashboard.retention.cohort_size": "New users",
|
"admin.dashboard.retention.cohort_size": "New users",
|
||||||
|
"admin.dimenssions.disabled_key": "This information is invalid.",
|
||||||
"admin.impact_report.instance_accounts": "Accounts profiles this would delete",
|
"admin.impact_report.instance_accounts": "Accounts profiles this would delete",
|
||||||
"admin.impact_report.instance_followers": "Followers our users would lose",
|
"admin.impact_report.instance_followers": "Followers our users would lose",
|
||||||
"admin.impact_report.instance_follows": "Followers their users would lose",
|
"admin.impact_report.instance_follows": "Followers their users would lose",
|
||||||
|
|
|
@ -88,6 +88,7 @@
|
||||||
"admin.dashboard.retention.average": "平均",
|
"admin.dashboard.retention.average": "平均",
|
||||||
"admin.dashboard.retention.cohort": "サインアップ月",
|
"admin.dashboard.retention.cohort": "サインアップ月",
|
||||||
"admin.dashboard.retention.cohort_size": "新しいユーザー",
|
"admin.dashboard.retention.cohort_size": "新しいユーザー",
|
||||||
|
"admin.dimenssions.disabled_key": "この情報は無効です。",
|
||||||
"admin.impact_report.instance_accounts": "プロフィール情報が削除されるアカウントの数",
|
"admin.impact_report.instance_accounts": "プロフィール情報が削除されるアカウントの数",
|
||||||
"admin.impact_report.instance_followers": "このサーバーのユーザーが失うフォロワー数",
|
"admin.impact_report.instance_followers": "このサーバーのユーザーが失うフォロワー数",
|
||||||
"admin.impact_report.instance_follows": "対象のサーバーのユーザーが失うフォロワー数",
|
"admin.impact_report.instance_follows": "対象のサーバーのユーザーが失うフォロワー数",
|
||||||
|
|
|
@ -14,6 +14,8 @@ class Admin::Metrics::Dimension
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
def self.retrieve(dimension_keys, start_at, end_at, limit, params)
|
def self.retrieve(dimension_keys, start_at, end_at, limit, params)
|
||||||
|
dimension_keys.delete('servers') unless HighLoadHelper.allow_high_load?
|
||||||
|
|
||||||
Array(dimension_keys).filter_map do |key|
|
Array(dimension_keys).filter_map do |key|
|
||||||
klass = DIMENSIONS[key.to_sym]
|
klass = DIMENSIONS[key.to_sym]
|
||||||
klass&.new(start_at, end_at, limit, klass.with_params? ? params.require(key.to_sym) : nil)
|
klass&.new(start_at, end_at, limit, klass.with_params? ? params.require(key.to_sym) : nil)
|
||||||
|
|
|
@ -19,6 +19,8 @@ class Admin::Metrics::Measure
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
def self.retrieve(measure_keys, start_at, end_at, params)
|
def self.retrieve(measure_keys, start_at, end_at, params)
|
||||||
|
measure_keys.delete('instance_statuses') unless HighLoadHelper.allow_high_load?
|
||||||
|
|
||||||
Array(measure_keys).filter_map do |key|
|
Array(measure_keys).filter_map do |key|
|
||||||
klass = MEASURES[key.to_sym]
|
klass = MEASURES[key.to_sym]
|
||||||
klass&.new(start_at, end_at, klass.with_params? ? params.require(key.to_sym) : nil)
|
klass&.new(start_at, end_at, klass.with_params? ? params.require(key.to_sym) : nil)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue