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

Speed up /entire/weapons2 #706

Closed
wants to merge 10 commits into from
Closed
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
168 changes: 0 additions & 168 deletions .circleci/config.yml

This file was deleted.

2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
strategy:
matrix:
php_version:
- '7.3'
- '7.4'
runs-on: 'ubuntu-latest'
needs:
Expand Down Expand Up @@ -89,7 +88,6 @@ jobs:
strategy:
matrix:
php_version:
- '7.3'
- '7.4'
pgsql_version:
- '9.5-alpine' # minimum requirement
Expand Down
34 changes: 17 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ RUN rpm --import \
make \
nodejs \
patch \
php73-php-cli \
php73-php-fpm \
php73-php-gd \
php73-php-intl \
php73-php-json \
php73-php-mbstring \
php73-php-mcrypt \
php73-php-opcache \
php73-php-pdo \
php73-php-pecl-msgpack \
php73-php-pecl-zip \
php73-php-pgsql \
php73-php-process \
php73-php-xml \
php73-runtime \
php74-php-cli \
php74-php-fpm \
php74-php-gd \
php74-php-intl \
php74-php-json \
php74-php-mbstring \
php74-php-mcrypt \
php74-php-opcache \
php74-php-pdo \
php74-php-pecl-msgpack \
php74-php-pecl-zip \
php74-php-pgsql \
php74-php-process \
php74-php-xml \
php74-runtime \
rh-postgresql95-postgresql \
rh-postgresql95-postgresql-server \
supervisor \
Expand All @@ -72,7 +72,7 @@ USER postgres
RUN scl enable rh-postgresql95 'initdb --pgdata=/var/opt/rh/rh-postgresql95/lib/pgsql/data --encoding=UNICODE --locale=en_US.UTF8'
ADD docker/database/pg_hba.conf /var/opt/rh/rh-postgresql95/lib/pgsql/data/pg_hba.conf
ADD docker/database/password.php /var/opt/rh/rh-postgresql95/lib/pgsql/
RUN scl enable rh-postgresql95 php73 ' \
RUN scl enable rh-postgresql95 php74 ' \
/opt/rh/rh-postgresql95/root/usr/libexec/postgresql-ctl start -D /var/opt/rh/rh-postgresql95/lib/pgsql/data -s -w && \
createuser -DRS statink && \
createdb -E UNICODE -O statink -T template0 statink && \
Expand All @@ -88,7 +88,7 @@ RUN cd ~statink/stat.ink && \
su postgres -c "/opt/rh/rh-postgresql95/root/usr/libexec/postgresql-ctl stop -D /var/opt/rh/rh-postgresql95/lib/pgsql/data -s -m fast"'

ADD docker/php/php-config.diff /tmp/
RUN patch -p1 -d /etc/opt/remi/php73 < /tmp/php-config.diff && rm /tmp/php-config.diff
RUN patch -p1 -d /etc/opt/remi/php74 < /tmp/php-config.diff && rm /tmp/php-config.diff

ADD docker/h2o/h2o.conf /etc/h2o/h2o.conf

Expand Down
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Use a private channel if it is a security issue.
REQUIREMENTS
------------

- PHP 7.3+ (Recommended: 7.4+)
- Doesn't work with 7.2 or lower. (Uses statements and constants added in v7.3)
- PHP 7.4+
- Doesn't work with 7.3 or lower. (Uses statements and constants added in v7.4, such as arrow function and typed property)
- You should build/install with Argon2. [Install `php-sodium` if you use remirepo's PHP 7.4](https://github.com/remicollet/remirepo/issues/132#issuecomment-566513636).
- PostgreSQL 9.5+ (Recommended: 11+)
- Doesn't work with 9.4 or lower. (Uses features added in v9.5)
Expand Down Expand Up @@ -72,11 +72,8 @@ https://stat.ink/ works with:

Notes:

- We will soon be changing the minimum requirement to PHP 7.4.
The author wants to use the [typed properties](https://www.php.net/manual/en/migration74.new-features.php#migration74.new-features.core.typed-properties).

- Default version of PHP on CentOS 7 is 5.4.16. This application doesn't work on it.
We are using features and statements that were added up to PHP 7.3.
We are using features and statements that were added up to PHP 7.4.

- Default version of PostgreSQL on CentOS 7 is 9.2.14. This application doesn't work with it.
We are using features added in PostgreSQL 9.5 (e.g., jsonb, UPSERT).
Expand Down
35 changes: 15 additions & 20 deletions actions/entire/Weapons2Action.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* @copyright Copyright (C) 2015-2019 AIZAWA Hina
* @copyright Copyright (C) 2015-2020 AIZAWA Hina
* @license https://github.com/fetus-hina/stat.ink/blob/master/LICENSE MIT
* @author AIZAWA Hina <hina@fetus.jp>
*/
Expand All @@ -10,7 +10,6 @@

namespace app\actions\entire;

use stdClass;
use DateInterval;
use DateTime;
use DateTimeImmutable;
Expand All @@ -25,15 +24,20 @@
use app\models\StatWeapon2UseCount;
use app\models\Subweapon2;
use app\models\Weapon2;
use stdClass;
use yii\db\Query;
use yii\web\ViewAction as BaseAction;
use yii\web\ViewAction;

class Weapons2Action extends BaseAction
class Weapons2Action extends ViewAction
{
public function run()
{
$form = Yii::createObject(['class' => EntireWeapon2Form::class]);
$form->load($_GET) && $form->validate();
$form = Yii::createObject([
'__class' => EntireWeapon2Form::class,
]);
if (!$form->load($_GET) || !$form->validate()) {
$form->updateToDefault();
}

return $this->controller->render('weapons2', [
'form' => $form,
Expand Down Expand Up @@ -247,21 +251,12 @@ private function getEntireWeaponsByRule(Rule2 $rule, EntireWeapon2Form $form)
'{{map2}}.[[key]]' => $form->map,
]);
}
if ($form->term == '') {
if (
$form->term === null ||
$form->term === '' ||
$form->term === '*'
) {
// nothing to do
} elseif (preg_match('/^(\d{4})-(\d{2})$/', $form->term, $match)) {
// [$start, $end)
$start = (new DateTimeImmutable())
->setTimeZone(new DateTimeZone('Etc/UTC'))
->setDate(intval($match[1], 10), intval($match[2], 10), 1)
->setTime(0, 0, 0);
$end = $start->add(new DateInterval('P1M'));
$startPeriod = BattleHelper::calcPeriod2($start->getTimestamp());
$endPeriod = BattleHelper::calcPeriod2($end->getTimestamp());
$query->andWhere(['and',
['>=', '{{stat_weapon2_use_count}}.[[period]]', $startPeriod],
['<', '{{stat_weapon2_use_count}}.[[period]]', $endPeriod],
]);
} elseif (substr($form->term, 0, 1) === 'v') {
if (!$v1 = SplatoonVersion2::findOne(['tag' => substr($form->term, 1)])) {
throw new \Exception();
Expand Down
6 changes: 5 additions & 1 deletion commands/StatController.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* @copyright Copyright (C) 2015-2019 AIZAWA Hina
* @copyright Copyright (C) 2015-2020 AIZAWA Hina
* @license https://github.com/fetus-hina/stat.ink/blob/master/LICENSE MIT
* @author AIZAWA Hina <hina@fetus.jp>
*/
Expand Down Expand Up @@ -46,6 +46,7 @@

class StatController extends Controller
{
use stat\StatWeapon2EntireTrait;
use stat\Weapon2Trait;

/**
Expand All @@ -55,6 +56,9 @@ class StatController extends Controller
*/
public function actionUpdateEntireWeapons()
{
$this->updateStatWeapon2Entire();
return; //FIXME

// $this->updateEntireWeapons1();
$this->updateEntireWeapons2();
}
Expand Down
Loading