mirror of
https://github.com/cydrobolt/polr.git
synced 2024-11-09 11:42:28 +01:00
Fixing performance issue when having millions of links already generated.
This commit is contained in:
parent
6e73538257
commit
ab4eb42a30
@ -118,9 +118,12 @@ class LinkHelper {
|
||||
*/
|
||||
$base = env('POLR_BASE');
|
||||
|
||||
$link = Link::where('is_custom', 0)
|
||||
/*$link = Link::where('is_custom', 0)
|
||||
->orderBy('created_at', 'desc')
|
||||
->first();
|
||||
->first();*/
|
||||
|
||||
// This change works quite faster after an index creation on is_custom
|
||||
$link = Link::whereRaw('id = (SELECT max(id) FROM links WHERE is_custom = 0)')->get()->first();
|
||||
|
||||
if ($link == null) {
|
||||
$base10_val = 0;
|
||||
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddLinkTableIndexOnIsCustom extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('links', function (Blueprint $table)
|
||||
{
|
||||
// This index helps to find quickly the last ending generated
|
||||
$table->index('is_custom', 'links_is_custom_index');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::table('links', function (Blueprint $table)
|
||||
{
|
||||
$table->dropIndex('is_custom');
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user