Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: 管理画面で特に負荷の大きい処理を無効にする環境変数 #633

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/helpers/high_load_helper.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 11 additions & 3 deletions app/javascript/mastodon/components/admin/Counter.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import { PureComponent } from 'react';

import { FormattedNumber } from 'react-intl';
import { FormattedNumber, FormattedMessage } from 'react-intl';

import classNames from 'classnames';

Expand Down Expand Up @@ -43,6 +43,7 @@ export default class Counter extends PureComponent {
state = {
loading: true,
data: null,
empty: false,
};

componentDidMount () {
Expand All @@ -52,6 +53,7 @@ export default class Counter extends PureComponent {
this.setState({
loading: false,
data: res.data,
empty: res.data.length === 0,
});
}).catch(err => {
console.error(err);
Expand All @@ -60,7 +62,7 @@ export default class Counter extends PureComponent {

render () {
const { label, href, target } = this.props;
const { loading, data } = this.state;
const { loading, data, empty } = this.state;

let content;

Expand All @@ -71,6 +73,12 @@ export default class Counter extends PureComponent {
<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 {
const measure = data[0];
const percentChange = measure.previous_total && percIncrease(measure.previous_total * 1, measure.total * 1);
Expand All @@ -94,7 +102,7 @@ export default class Counter extends PureComponent {
</div>

<div className='sparkline__graph'>
{!loading && (
{!loading && !empty && (
<Sparklines width={259} height={55} data={data[0].data.map(x => x.value * 1)}>
<SparklinesCurve />
</Sparklines>
Expand Down
18 changes: 16 additions & 2 deletions app/javascript/mastodon/components/admin/Dimension.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import { PureComponent } from 'react';

import { FormattedNumber } from 'react-intl';
import { FormattedNumber, FormattedMessage } from 'react-intl';

import api from 'mastodon/api';
import { Skeleton } from 'mastodon/components/skeleton';
Expand All @@ -21,6 +21,7 @@ export default class Dimension extends PureComponent {
state = {
loading: true,
data: null,
empty: false,
};

componentDidMount () {
Expand All @@ -30,6 +31,7 @@ export default class Dimension extends PureComponent {
this.setState({
loading: false,
data: res.data,
empty: res.data.length === 0,
});
}).catch(err => {
console.error(err);
Expand All @@ -38,7 +40,7 @@ export default class Dimension extends PureComponent {

render () {
const { label, limit } = this.props;
const { loading, data } = this.state;
const { loading, data, empty } = this.state;

let content;

Expand All @@ -60,6 +62,18 @@ export default class Dimension extends PureComponent {
</tbody>
</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 {
const sum = data[0].data.reduce((sum, cur) => sum + (cur.value * 1), 0);

Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"admin.dashboard.retention.average": "Average",
"admin.dashboard.retention.cohort": "Sign-up month",
"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_followers": "Followers our users would lose",
"admin.impact_report.instance_follows": "Followers their users would lose",
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"admin.dashboard.retention.average": "平均",
"admin.dashboard.retention.cohort": "サインアップ月",
"admin.dashboard.retention.cohort_size": "新しいユーザー",
"admin.dimenssions.disabled_key": "この情報は無効です。",
"admin.impact_report.instance_accounts": "プロフィール情報が削除されるアカウントの数",
"admin.impact_report.instance_followers": "このサーバーのユーザーが失うフォロワー数",
"admin.impact_report.instance_follows": "対象のサーバーのユーザーが失うフォロワー数",
Expand Down
2 changes: 2 additions & 0 deletions app/lib/admin/metrics/dimension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Admin::Metrics::Dimension
}.freeze

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|
klass = DIMENSIONS[key.to_sym]
klass&.new(start_at, end_at, limit, klass.with_params? ? params.require(key.to_sym) : nil)
Expand Down
2 changes: 2 additions & 0 deletions app/lib/admin/metrics/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class Admin::Metrics::Measure
}.freeze

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|
klass = MEASURES[key.to_sym]
klass&.new(start_at, end_at, klass.with_params? ? params.require(key.to_sym) : nil)
Expand Down
Loading