Skip to content

Commit

Permalink
Merge branch 'master' into contest-judging
Browse files Browse the repository at this point in the history
  • Loading branch information
venix12 committed Nov 30, 2023
2 parents 4a395fe + 57c0c30 commit b68a1dd
Show file tree
Hide file tree
Showing 1,034 changed files with 12,604 additions and 6,370 deletions.
10 changes: 8 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ DB_USERNAME=osuweb
# REDIS_HOST=127.0.0.1
# REDIS_PORT=6379
# REDIS_DB=0
# REDIS_PASSWORD=

# CACHE_REDIS_HOST=127.0.0.1
# CACHE_REDIS_PORT=6379
# CACHE_REDIS_DB=0
# CACHE_REDIS_PASSWORD=

# MEMCACHED_PERSISTENT_ID=
# MEMCACHED_USERNAME=
Expand Down Expand Up @@ -100,8 +102,6 @@ SLACK_ENDPOINT=https://myconan.net/null/
# ISSUE_FORUM_IDS=
# FORUM_POST_MINIMUM_PLAYS=200

# GA_TRACKING_ID=UA-xxx

PUSHER_APP_ID=
PUSHER_KEY=
PUSHER_SECRET=
Expand All @@ -112,6 +112,11 @@ PUSHER_SECRET=

# GITHUB_TOKEN=

# GitHub client for users to associate their GitHub accounts
# Use "<APP_URL>/home/account/github-users/callback" for the "Authorization callback URL" field on GitHub
# GITHUB_CLIENT_ID=
# GITHUB_CLIENT_SECRET=

# DATADOG_ENABLED=true
# DATADOG_PREFIX=osu.web
# DATADOG_API_KEY=
Expand Down Expand Up @@ -250,6 +255,7 @@ CLIENT_CHECK_VERSION=false
# NOTIFICATION_REDIS_HOST=127.0.0.1
# NOTIFICATION_REDIS_PORT=6379
# NOTIFICATION_REDIS_DB=0
# NOTIFICATION_REDIS_PASSWORD=
# NOTIFICATION_SERVER_LISTEN_HOST=127.0.0.1
# NOTIFICATION_SERVER_LISTEN_PORT=3000
# NOTIFICATION_ENDPOINT=/home/notifications/feed
Expand Down
4 changes: 1 addition & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ module.exports = {
'@typescript-eslint/object-curly-spacing': ['error', 'always'],
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-readonly': 'error',
'@typescript-eslint/quotes': [
'error',
'single',
Expand All @@ -125,10 +126,7 @@ module.exports = {
'@typescript-eslint/strict-boolean-expressions': [
'error',
{
allowAny: true,
allowNullableBoolean: true,
allowNullableNumber: true,
allowNullableString: true,
},
],
'@typescript-eslint/type-annotation-spacing': 'error',
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set php version
uses: shivammathur/setup-php@v2
with:
tools: composer:v2
tools: composer:v2, cs2pr
php-version: '8.2'
coverage: none

Expand All @@ -49,11 +49,9 @@ jobs:
- name: Install js dependencies
run: yarn --frozen-lockfile

- run: 'yarn lint --max-warnings 96 > /dev/null'
- run: 'yarn lint --max-warnings 94 > /dev/null'

- run: ./bin/update_licence.sh -nf

- name: Run PHPCS
run: |
echo "::add-matcher::${PWD}/.github/workflows/lint/problem-matcher.json"
./vendor/bin/phpcs --report=checkstyle --basepath="$PWD"
run: ./vendor/bin/phpcs --report=checkstyle --basepath="$PWD" -q | cs2pr
23 changes: 0 additions & 23 deletions .github/workflows/lint/problem-matcher.json

This file was deleted.

3 changes: 0 additions & 3 deletions .github/workflows/lint/readme.txt

This file was deleted.

12 changes: 6 additions & 6 deletions .github/workflows/pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
-
name: Docker meta
id: meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
Expand All @@ -38,16 +38,16 @@ jobs:
latest=false
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
-
name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Build and push
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
build-args: |
"APP_URL=https://osu.ppy.sh"
Expand Down Expand Up @@ -104,7 +104,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
-
name: Repository Dispatch
uses: peter-evans/repository-dispatch@v2
Expand Down
83 changes: 54 additions & 29 deletions app/Console/Commands/ModdingRankCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace App\Console\Commands;

use App\Models\Beatmap;
use App\Enums\Ruleset;
use App\Models\Beatmapset;
use Illuminate\Console\Command;

Expand All @@ -16,7 +16,7 @@ class ModdingRankCommand extends Command
*
* @var string
*/
protected $signature = 'modding:rank';
protected $signature = 'modding:rank {--no-wait} {--count-only}';

/**
* The console command description.
Expand All @@ -25,60 +25,81 @@ class ModdingRankCommand extends Command
*/
protected $description = 'Rank maps in queue.';

private bool $countOnly = false;
private bool $noWait = false;

public static function getStats(Ruleset $ruleset)
{
$rankedTodayCount = Beatmapset::ranked()
->withoutTrashed()
->withModesForRanking($ruleset->value)
->where('approved_date', '>=', now()->subDays())
->count();

return [
'availableQuota' => config('osu.beatmapset.rank_per_day') - $rankedTodayCount,
'inQueue' => Beatmapset::toBeRanked($ruleset)->count(),
'rankedToday' => $rankedTodayCount,
];
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->info('Ranking beatmapsets...');
$this->countOnly = get_bool($this->option('count-only'));
$this->noWait = get_bool($this->option('no-wait'));

$modeInts = array_values(Beatmap::MODES);
if ($this->countOnly) {
$this->info('Number of beatmapsets in queue:');
} else {
$this->info('Ranking beatmapsets...');
}

$rulesets = Ruleset::cases();

shuffle($modeInts);
shuffle($rulesets);

foreach ($modeInts as $modeInt) {
foreach ($rulesets as $ruleset) {
$this->waitRandom();
$this->rankAll($modeInt);

if ($this->countOnly) {
$stats = static::getStats($ruleset);
$this->info($ruleset->name);
foreach ($stats as $key => $value) {
$this->line("{$key}: {$value}");
}
$this->newLine();
} else {
$this->rankAll($ruleset);
}
}

$this->info('Done');
}

private function rankAll($modeInt)
private function rankAll(Ruleset $ruleset)
{
$this->info('Ranking beatmapsets with at least mode: '.Beatmap::modeStr($modeInt));
$this->info("Ranking beatmapsets with at least mode: {$ruleset->name}");
$stats = static::getStats($ruleset);

$rankedTodayCount = Beatmapset::ranked()
->withoutTrashed()
->withModesForRanking($modeInt)
->where('approved_date', '>=', now()->subDays())
->count();

$rankableQuota = config('osu.beatmapset.rank_per_day') - $rankedTodayCount;

$this->info("{$rankedTodayCount} beatmapsets ranked last 24 hours. Can rank {$rankableQuota} more");
$this->info("{$stats['rankedToday']} beatmapsets ranked last 24 hours. Can rank {$stats['availableQuota']} more");

if ($rankableQuota <= 0) {
if ($stats['availableQuota'] <= 0) {
return;
}

$toRankLimit = min(config('osu.beatmapset.rank_per_run'), $rankableQuota);
$toRankLimit = min(config('osu.beatmapset.rank_per_run'), $stats['availableQuota']);

$toBeRankedQuery = Beatmapset::qualified()
->withoutTrashed()
->withModesForRanking($modeInt)
->where('queued_at', '<', now()->subDays(config('osu.beatmapset.minimum_days_for_rank')));

$rankingQueue = $toBeRankedQuery->count();

$toBeRanked = $toBeRankedQuery
$toBeRanked = Beatmapset::tobeRanked($ruleset)
->orderBy('queued_at', 'ASC')
->limit($toRankLimit)
->get();

$this->info("{$rankingQueue} beatmapset(s) in ranking queue");
$this->info("{$stats['inQueue']} beatmapset(s) in ranking queue");
$this->info("Ranking {$toBeRanked->count()} beatmapset(s)");

foreach ($toBeRanked as $beatmapset) {
Expand All @@ -90,6 +111,10 @@ private function rankAll($modeInt)

private function waitRandom()
{
if ($this->noWait || $this->countOnly) {
return;
}

$delay = rand(5, 120);
$this->info("Pausing for {$delay} seconds...");
sleep($delay);
Expand Down
31 changes: 31 additions & 0 deletions app/Docs/Strategies/UsesCursor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Docs\Strategies;

use Knuckles\Camel\Extraction\ExtractedEndpointData;
use Knuckles\Scribe\Extracting\RouteDocBlocker;
use Knuckles\Scribe\Extracting\Strategies\Strategy;

class UsesCursor extends Strategy
{
public function __invoke(ExtractedEndpointData $endpointData, array $routeRules = []): ?array
{
$docBlock = RouteDocBlocker::getDocBlocksFromRoute($endpointData->route)['method'];
$tags = $docBlock->getTagsByName('usesCursor');

return empty($tags)
? []
: [
'cursor_string' => [
'description' => '[CursorString](#cursorstring) for pagination.',
'required' => false,
'example' => null,
],
];
}
}
2 changes: 1 addition & 1 deletion app/Libraries/Ip.php → app/Enums/Ip.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

declare(strict_types=1);

namespace App\Libraries;
namespace App\Enums;

enum Ip: string
{
Expand Down
44 changes: 44 additions & 0 deletions app/Enums/Ruleset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Enums;

enum Ruleset: int
{
case osu = 0;
case taiko = 1;
case catch = 2;
case mania = 3;

// for usage with tryFrom when the parameter may be null.
public const NULL = -1;

public static function tryFromName(?string $ruleset): ?self
{
if ($ruleset === null) {
return null;
}

static $lookupMap;
if ($lookupMap === null) {
$lookupMap = [];
foreach (self::cases() as $r) {
$lookupMap[$r->name] = $r;
}
$lookupMap['fruits'] = self::catch;
}

return $lookupMap[$ruleset] ?? null;
}

public function legacyName()
{
return $this === self::catch
? 'fruits'
: $this->name;
}
}
5 changes: 0 additions & 5 deletions app/Events/BroadcastableEventBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace App\Events;

use App\Libraries\BroadcastsPendingForTests;
use DB;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

Expand All @@ -20,10 +19,6 @@ abstract class BroadcastableEventBase implements ShouldBroadcast
public function broadcast(bool $afterCommit = false)
{
if ($afterCommit) {
if (app()->environment('testing')) {
app(BroadcastsPendingForTests::class)->add($this);
}

DB::afterCommit(fn () => event($this));
} else {
event($this);
Expand Down
Loading

0 comments on commit b68a1dd

Please sign in to comment.