我正在使用laravel创建一个MLM应用程序,并使用https://github.com/staudenmeir/laravel-adjacency-list
我的桌子很简单,如下:
Schema::create('user_relations', function (Blueprint $table) {
$table->integer('id')->primary();
$table->integer('parent_id');
$table->integer('status')->default(0);
$table->timestamps();
$table->softDeletes();
});
我正在像这样运行查询:
$total = \App\User_relation::find($parent_id);
if ($total)
return $total->descendants()->count();
return 0;
用户关系模型:
namespace App;
use Illuminate\Database\Eloquent\Model;
use Staudenmeir\LaravelAdjacencyList\Eloquent\HasRecursiveRelationships;
class User_relation extends Model
{
use HasRecursiveRelationships;
}
它可以正常工作多达13000条记录,但是我正在测试具有相同代码的36000条记录,并且它将永远加载。可能是什么问题,我该如何解决?用13000条记录进行测试时,耗时186秒。