1
0
mirror of https://github.com/cydrobolt/polr.git synced 2024-09-20 23:51:53 +02:00

Merge branch 'iurisilvio-api_quota_index'

This commit is contained in:
Chaoyi Zha 2018-01-07 22:50:26 -05:00
commit d33cb1c5b3
2 changed files with 41 additions and 1 deletions

View File

@ -23,11 +23,15 @@ class ApiHelper {
$api_quota = env('SETTING_ANON_API_QUOTA') ?: 5;
}
if ($api_quota < 0) {
return false;
}
$links_last_minute = Link::where('is_api', 1)
->where('creator', $username)
->where('created_at', '>=', $last_minute)
->count();
return ($api_quota > -1 && $links_last_minute >= $api_quota);
return $links_last_minute >= $api_quota;
}
}

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateApiQuotaIndex extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('links', function (Blueprint $table)
{
$table->index(
['created_at', 'creator', 'is_api'],
'api_quota_index'
);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('links', function (Blueprint $table)
{
$table->dropIndex('api_quota_index');
});
}
}