Skip to content

Commit 0503e40

Browse files
authored
Merge branch 'master' into more-random
2 parents 7a2cd52 + b98fc78 commit 0503e40

File tree

6 files changed

+63
-15
lines changed

6 files changed

+63
-15
lines changed

app/Http/Controllers/LegacyMatchesController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ public function __construct()
3636
* matches | [Match](#match)[] | |
3737
* params.limit | integer | |
3838
* params.sort | string | |
39+
* params.active | boolean? | |
3940
*
4041
* @usesCursor
4142
* @queryParam limit integer Maximum number of matches (50 default, 1 minimum, 50 maximum). No-example
4243
* @queryParam sort string `id_desc` for newest first; `id_asc` for oldest first. Defaults to `id_desc`. No-example
44+
* @queryParam active boolean `true` for active matches only; `false` for inactive matches only. Defaults to not specified, returning both. No-example
4345
* @response {
4446
* "matches": [
4547
* {
@@ -52,7 +54,8 @@ public function __construct()
5254
* ],
5355
* "params": {
5456
* "limit": 50,
55-
* "sort": "id_desc"
57+
* "sort": "id_desc",
58+
* "active": null
5659
* },
5760
* "cursor": {
5861
* "match_id": 114428685

app/Http/Middleware/AuthApi.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ private function validTokenFromRequest($psr)
8383
$token->setRelation('client', $client);
8484
$token->validate();
8585

86+
// increment hit count for about every 10 hits
87+
if (rand(0, 9) === 0) {
88+
$token->incrementInstance('hit_count', 10);
89+
}
90+
8691
$user = $token->getResourceOwner();
8792

8893
if ($token->isClientCredentials()) {

app/Models/Model.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
abstract class Model extends BaseModel
2121
{
22-
use HasFactory, Traits\FasterAttributes, Validatable;
22+
use HasFactory, Traits\FasterAttributes, Traits\IncrementInstance, Validatable;
2323

2424
const MAX_FIELD_LENGTHS = [];
2525
const int PER_PAGE = 50;
@@ -201,18 +201,6 @@ public function delete()
201201
});
202202
}
203203

204-
/**
205-
* Just like increment but only works on saved instance instead of falling back to entire model
206-
*/
207-
public function incrementInstance()
208-
{
209-
if (!$this->exists) {
210-
return false;
211-
}
212-
213-
return $this->increment(...func_get_args());
214-
}
215-
216204
public function save(array $options = [])
217205
{
218206
return $this->runAfterCommitWrapper(function () use ($options) {

app/Models/OAuth/Token.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\Exceptions\InvalidScopeException;
1010
use App\Interfaces\SessionVerificationInterface;
1111
use App\Models\Traits\FasterAttributes;
12+
use App\Models\Traits\IncrementInstance;
1213
use App\Models\User;
1314
use Ds\Set;
1415
use Illuminate\Database\Eloquent\Factories\HasFactory;
@@ -18,7 +19,7 @@
1819
class Token extends PassportToken implements SessionVerificationInterface
1920
{
2021
// PassportToken doesn't have factory
21-
use HasFactory, FasterAttributes;
22+
use HasFactory, FasterAttributes, IncrementInstance;
2223

2324
const SCOPES_CLIENT_CREDENTIALS_ONLY = ['delegate', 'forum.write_manage', 'group_permissions'];
2425
const SCOPES_EXCLUDE_FROM_ALL = ['delegate', 'group_permissions'];
@@ -76,6 +77,7 @@ public function getAttribute($key)
7677
{
7778
return match ($key) {
7879
'client_id',
80+
'hit_count',
7981
'id',
8082
'name',
8183
'user_id',
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4+
// See the LICENCE file in the repository root for full licence text.
5+
6+
declare(strict_types=1);
7+
8+
namespace App\Models\Traits;
9+
10+
trait IncrementInstance
11+
{
12+
/**
13+
* Just like increment but only works on saved instance instead of falling back to entire model
14+
*/
15+
public function incrementInstance()
16+
{
17+
if (!$this->exists) {
18+
return false;
19+
}
20+
21+
return $this->increment(...func_get_args());
22+
}
23+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4+
// See the LICENCE file in the repository root for full licence text.
5+
6+
declare(strict_types=1);
7+
8+
use Illuminate\Database\Migrations\Migration;
9+
use Illuminate\Database\Schema\Blueprint;
10+
use Illuminate\Support\Facades\Schema;
11+
12+
return new class extends Migration
13+
{
14+
public function up(): void
15+
{
16+
Schema::table('oauth_access_tokens', function (Blueprint $table) {
17+
$table->unsignedBigInteger('hit_count')->default(0);
18+
});
19+
}
20+
21+
public function down(): void
22+
{
23+
Schema::table('oauth_access_tokens', function (Blueprint $table) {
24+
$table->dropColumn('hit_count');
25+
});
26+
}
27+
};

0 commit comments

Comments
 (0)