GNU socialの添付ファイル・画像のアップロードサイズ設定

GNU social v2で画像を添付して投稿しようとすると、以下のエラーが発生した。
A file this large would exceed your user quota of 50000000 bytes.
メッセージ通り、ユーザー割当容量の50 MBを超過してしまったため投稿できなくなったようだ。
このエラーについては、「A file this large would exceed your user quota of 50000000 bytes. – NotABug.org: Free code hosting」でも議論されており、GNU socialの設定でサイズを調整できるらしい。設定項目が3種類あるので整理する (CONFIGURE.md#attachments)。
| 項目 | 初期値 | 説明 | 
|---|---|---|
| file_quota | PHPの設定 (common_get_preferred_php_upload_limit()) | 単一ファイルのアップロードサイズ上限 (Byte単位)。 | 
| user_quota | 50000000 | サーバーに保存可能な単一ユーザーの合計サイズ上限 (Byte単位)。 | 
| monthly_quota | 15000000 | 1か月あたりの単一ユーザーの投稿合計サイズ上限。 | 
初期値の値はlib/util/default.phpに記載がある (参考: GNU socialのデフォルト設定 – Kenchant)。
実際に、エラーを出している箇所は classes/File.phpの260行目付近の以下のコードのようだ。
        $query = "SELECT sum(size) AS total
                  FROM file
                       INNER JOIN file_to_post
                              ON file_to_post.file_id = file.id
                       INNER JOIN notice
                              ON file_to_post.post_id = notice.id
                  WHERE profile_id = {$scoped->id} AND
                        filename IS NULL AND
                        file.url IS NOT NULL";
        $file->query($query);
        $file->fetch();
        $total = $file->total + $fileSize;
        if ($total > common_config('attachments', 'user_quota')) {
            // TRANS: Message given if an upload would exceed user quota.
            // TRANS: %d (number) is the user quota in bytes and is used for plural.
            throw new ClientException(
                sprintf(
                    _m(
                        'A file this large would exceed your user quota of %d byte.',
                        'A file this large would exceed your user quota of %d bytes.',
                        common_config('attachments', 'user_quota')
                    ),
                    common_config('attachments', 'user_quota')
                )
            );
        }直前で指定されているSQLが以下ののような内容になる。
select sum(size) as total from file
  inner join file_to_post on file_to_post.file_id = file.id inner join notice on file_to_post.post_id = notice.id
  where profile_id = 1 and filename is null and file.url is not nullprofile_idの数字は、GNU socialのプロフィール画面に表示される [User ID] の値を指定する。
これを実際に自分のDBで実行してみると、 [221227041] の数字が表示された。バイト単位なのでMBに直すと221 MBとなる。こんなに大量の画像を投稿した覚えはないのだが、こうなっていた。
select文のところをselect * from fileに変更して集計対象のレコードを確認すると、添付画像やURLから自動生成されるサムネイル画像のサイズが集計されていた。これで納得した。
デフォルトだと450:600 pxのサイズで生成される。設定するなら150:200に小さくしたほうがいいか。
maxsizeというパラメーターで、widthとheightのどちらかが超過したら生成しない。これを0にするとサムネイル画像を生成しないので節約になる。
そこで以下の設定をconfig.phpに追記した。
$config['attachments']['user_quota'] = 300*1000*1000;
$config['thumbnail']['maxsize'] = 0;maxsizeの設定はなくなると、過去の添付画像もサムネイルを一括で生成するようだ。ディスク容量を節約するには必須の設定に感じた。
サムネイルがない場合、添付した画像がそのまま直接投稿に表示されるので特に実害はない。
そのほか、添付した画像は元の投稿を削除しても残るようで、どこかで手動で削除しないといけないのかもしれない。
ひとまず、user_quotaの値の増加と不要ファイルの削除などで、ディスクスペースを節約しながら運用したい。