Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing performance issue when having millions of links #636

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/Helpers/LinkHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,12 @@ static public function findSuitableEnding() {
*/
$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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
});
}
}