diff options
author | Chaoyi Zha <summermontreal@gmail.com> | 2018-01-08 06:50:26 +0300 |
---|---|---|
committer | Chaoyi Zha <summermontreal@gmail.com> | 2018-01-08 06:50:26 +0300 |
commit | d33cb1c5b32d5a5a7f7a5e49329ec3a65dc46e3a (patch) | |
tree | a93c4bd7f88b291146baf20ea0b0b9befe034d0c | |
parent | 2068eba42b74ae0b278ff1848c9d39c712bba609 (diff) | |
parent | 216f0c75c0286154fdb314f0a4054014f75c1439 (diff) |
Merge branch 'iurisilvio-api_quota_index'
-rw-r--r-- | app/Helpers/ApiHelper.php | 6 | ||||
-rw-r--r-- | database/migrations/2017_12_21_095425_create_api_quota_index.php | 36 |
2 files changed, 41 insertions, 1 deletions
diff --git a/app/Helpers/ApiHelper.php b/app/Helpers/ApiHelper.php index 5f629f8..6c751fe 100644 --- a/app/Helpers/ApiHelper.php +++ b/app/Helpers/ApiHelper.php @@ -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; } } diff --git a/database/migrations/2017_12_21_095425_create_api_quota_index.php b/database/migrations/2017_12_21_095425_create_api_quota_index.php new file mode 100644 index 0000000..471ec41 --- /dev/null +++ b/database/migrations/2017_12_21_095425_create_api_quota_index.php @@ -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'); + }); + } +} |