mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-15 21:32:49 +00:00
perf: 项目列表数据库查询优化
This commit is contained in:
parent
bcf1ad0870
commit
8b5409de5a
@ -1016,11 +1016,14 @@ class ProjectController extends AbstractController
|
||||
$builder->orderBy('project_tasks.' . $column, $direction);
|
||||
}
|
||||
// 任务可见性条件
|
||||
$builder->leftJoin('project_users', function ($query) {
|
||||
$query->on('project_tasks.project_id', '=', 'project_users.project_id')->where('project_users.owner', 1);
|
||||
$builder->leftJoin('project_users', function ($query) use($userid) {
|
||||
$query->on('project_tasks.project_id', '=', 'project_users.project_id');
|
||||
$query->where('project_users.owner', 1);
|
||||
$query->where('project_users.userid', $userid);
|
||||
});
|
||||
$builder->leftJoin('project_task_users as project_p_task_users', function ($query) {
|
||||
$builder->leftJoin('project_task_users as project_p_task_users', function ($query) use($userid) {
|
||||
$query->on('project_p_task_users.task_pid', '=', 'project_tasks.parent_id');
|
||||
$query->where('project_p_task_users.userid', $userid);
|
||||
});
|
||||
$builder->where(function ($query) use ($userid) {
|
||||
$query->where("project_tasks.visibility", 1);
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class UpdateOwnerAddIndexSome20231217 extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('project_users', function (Blueprint $table) {
|
||||
$table->index('userid');
|
||||
$table->index('project_id');
|
||||
$table->index(['project_id','userid']);
|
||||
//
|
||||
$table->index('owner');
|
||||
$table->integer('owner')->change();
|
||||
});
|
||||
Schema::table('project_tasks', function (Blueprint $table) {
|
||||
$table->index('parent_id');
|
||||
$table->index('dialog_id');
|
||||
$table->index('userid');
|
||||
//
|
||||
if (Schema::hasColumn('project_tasks', 'visibility')) {
|
||||
$table->integer('visibility')->change();
|
||||
}
|
||||
});
|
||||
Schema::table('project_task_users', function (Blueprint $table) {
|
||||
$table->index(['task_id','userid']);
|
||||
//
|
||||
$table->index('owner');
|
||||
$table->integer('owner')->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return voidw
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('project_users', function (Blueprint $table) {
|
||||
$table->dropIndex(['userid']);
|
||||
$table->dropIndex(['project_id']);
|
||||
$table->dropIndex(['owner']);
|
||||
$table->dropIndex(['project_id','userid']);
|
||||
});
|
||||
Schema::table('project_tasks', function (Blueprint $table) {
|
||||
$table->dropIndex(['parent_id']);
|
||||
$table->dropIndex(['dialog_id']);
|
||||
$table->dropIndex(['userid']);
|
||||
});
|
||||
Schema::table('project_task_users', function (Blueprint $table) {
|
||||
$table->dropIndex(['owner']);
|
||||
$table->dropIndex(['task_id','userid']);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user