mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-17 06:32:51 +00:00
perf: 项目列表数据库查询优化
This commit is contained in:
parent
bcf1ad0870
commit
8b5409de5a
@ -876,10 +876,10 @@ class ProjectController extends AbstractController
|
|||||||
public function column__one()
|
public function column__one()
|
||||||
{
|
{
|
||||||
User::auth();
|
User::auth();
|
||||||
//
|
//
|
||||||
$column_id = intval(Request::input('column_id'));
|
$column_id = intval(Request::input('column_id'));
|
||||||
$deleted = Request::input('deleted', 'no');
|
$deleted = Request::input('deleted', 'no');
|
||||||
//
|
//
|
||||||
$builder = ProjectColumn::whereId($column_id);
|
$builder = ProjectColumn::whereId($column_id);
|
||||||
if ($deleted == 'all') {
|
if ($deleted == 'all') {
|
||||||
$builder->withTrashed();
|
$builder->withTrashed();
|
||||||
@ -890,10 +890,10 @@ class ProjectController extends AbstractController
|
|||||||
if (empty($column)) {
|
if (empty($column)) {
|
||||||
return Base::retError('列表不存在');
|
return Base::retError('列表不存在');
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
return Base::retSuccess('success', $column);
|
return Base::retSuccess('success', $column);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {get} api/project/task/lists 19. 任务列表
|
* @api {get} api/project/task/lists 19. 任务列表
|
||||||
@ -1016,11 +1016,14 @@ class ProjectController extends AbstractController
|
|||||||
$builder->orderBy('project_tasks.' . $column, $direction);
|
$builder->orderBy('project_tasks.' . $column, $direction);
|
||||||
}
|
}
|
||||||
// 任务可见性条件
|
// 任务可见性条件
|
||||||
$builder->leftJoin('project_users', function ($query) {
|
$builder->leftJoin('project_users', function ($query) use($userid) {
|
||||||
$query->on('project_tasks.project_id', '=', 'project_users.project_id')->where('project_users.owner', 1);
|
$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->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) {
|
$builder->where(function ($query) use ($userid) {
|
||||||
$query->where("project_tasks.visibility", 1);
|
$query->where("project_tasks.visibility", 1);
|
||||||
@ -2219,21 +2222,21 @@ class ProjectController extends AbstractController
|
|||||||
$task_id = intval(Request::input('task_id'));
|
$task_id = intval(Request::input('task_id'));
|
||||||
$project_id = intval(Request::input('project_id'));
|
$project_id = intval(Request::input('project_id'));
|
||||||
$column_id = intval(Request::input('column_id'));
|
$column_id = intval(Request::input('column_id'));
|
||||||
//
|
//
|
||||||
$task = ProjectTask::userTask($task_id, true, true, 2);
|
$task = ProjectTask::userTask($task_id, true, true, 2);
|
||||||
//
|
//
|
||||||
if( $task->project_id == $project_id && $task->column_id == $column_id){
|
if( $task->project_id == $project_id && $task->column_id == $column_id){
|
||||||
return Base::retSuccess('移动成功', ['id' => $task_id]);
|
return Base::retSuccess('移动成功', ['id' => $task_id]);
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
$project = Project::userProject($project_id);
|
$project = Project::userProject($project_id);
|
||||||
$column = ProjectColumn::whereProjectId($project->id)->whereId($column_id)->first();
|
$column = ProjectColumn::whereProjectId($project->id)->whereId($column_id)->first();
|
||||||
if (empty($column)) {
|
if (empty($column)) {
|
||||||
return Base::retError('列表不存在');
|
return Base::retError('列表不存在');
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
$task->moveTask($project_id,$column_id);
|
$task->moveTask($project_id,$column_id);
|
||||||
//
|
//
|
||||||
return Base::retSuccess('移动成功', ['id' => $task_id]);
|
return Base::retSuccess('移动成功', ['id' => $task_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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