mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-13 12:02:51 +00:00
perf: 文件新增pids(上级ID递归)字段
This commit is contained in:
parent
7dd85b2ba6
commit
49e4f15bd1
@ -252,7 +252,7 @@ class FileController extends AbstractController
|
||||
'userid' => $userid,
|
||||
'created_id' => $user->userid,
|
||||
]);
|
||||
$file->save();
|
||||
$file->saveBeforePids();
|
||||
//
|
||||
$data = File::find($file->id);
|
||||
$data->pushMsg('add', $data);
|
||||
@ -305,7 +305,7 @@ class FileController extends AbstractController
|
||||
$data = AbstractModel::transaction(function() use ($file) {
|
||||
$content = FileContent::select(['content', 'text', 'size'])->whereFid($file->cid)->orderByDesc('id')->first();
|
||||
$file->size = $content?->size ?: 0;
|
||||
$file->save();
|
||||
$file->saveBeforePids();
|
||||
if ($content) {
|
||||
$content = $content->toArray();
|
||||
$content['fid'] = $file->id;
|
||||
@ -336,7 +336,7 @@ class FileController extends AbstractController
|
||||
*/
|
||||
public function move()
|
||||
{
|
||||
$user = User::auth();
|
||||
User::auth();
|
||||
//
|
||||
$ids = Request::input('ids');
|
||||
$pid = intval(Request::input('pid'));
|
||||
@ -369,7 +369,7 @@ class FileController extends AbstractController
|
||||
}
|
||||
//
|
||||
$file->pid = $pid;
|
||||
$file->save();
|
||||
$file->saveBeforePids();
|
||||
$files[] = $file;
|
||||
}
|
||||
});
|
||||
@ -666,7 +666,7 @@ class FileController extends AbstractController
|
||||
'userid' => $userid,
|
||||
'created_id' => $user->userid,
|
||||
]);
|
||||
if ($dirRow->save()) {
|
||||
if ($dirRow->saveBeforePids()) {
|
||||
$pushMsg[] = File::find($dirRow->id);
|
||||
}
|
||||
}
|
||||
@ -735,7 +735,7 @@ class FileController extends AbstractController
|
||||
// 开始创建
|
||||
return AbstractModel::transaction(function () use ($webkitRelativePath, $type, $user, $data, $file) {
|
||||
$file->size = $data['size'] * 1024;
|
||||
$file->save();
|
||||
$file->saveBeforePids();
|
||||
//
|
||||
$data = Base::uploadMove($data, "uploads/file/" . $file->type . "/" . date("Ym") . "/" . $file->id . "/");
|
||||
$content = FileContent::createInstance([
|
||||
|
||||
@ -13,6 +13,7 @@ use Request;
|
||||
* App\Models\File
|
||||
*
|
||||
* @property int $id
|
||||
* @property string|null $pids 上级ID递归
|
||||
* @property int|null $pid 上级ID
|
||||
* @property int|null $cid 复制ID
|
||||
* @property string|null $name 名称
|
||||
@ -37,6 +38,7 @@ use Request;
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|File whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|File whereName($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|File wherePid($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|File wherePids($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|File whereShare($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|File whereSize($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|File whereType($value)
|
||||
@ -176,6 +178,40 @@ class File extends AbstractModel
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前更新pids
|
||||
* @return bool
|
||||
*/
|
||||
public function saveBeforePids()
|
||||
{
|
||||
$pid = $this->pid;
|
||||
$array = [];
|
||||
while ($pid > 0) {
|
||||
$array[] = $pid;
|
||||
$pid = intval(self::whereId($pid)->value('pid'));
|
||||
}
|
||||
$opids = $this->pids;
|
||||
if ($array) {
|
||||
$array = array_values(array_reverse($array));
|
||||
$this->pids = ',' . implode(',', $array) . ',';
|
||||
} else {
|
||||
$this->pids = '';
|
||||
}
|
||||
if (!$this->save()) {
|
||||
return false;
|
||||
}
|
||||
// 更新子文件(夹)
|
||||
if ($opids != $this->pids) {
|
||||
self::wherePid($this->id)->chunkById(100, function ($lists) {
|
||||
/** @var self $item */
|
||||
foreach ($lists as $item) {
|
||||
$item->saveBeforePids();
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 遍历删除文件(夹)
|
||||
* @return bool
|
||||
|
||||
45
database/migrations/2022_03_30_070029_add_files_pids.php
Normal file
45
database/migrations/2022_03_30_070029_add_files_pids.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddFilesPids extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$isAdd = false;
|
||||
Schema::table('files', function (Blueprint $table) use (&$isAdd) {
|
||||
if (!Schema::hasColumn('files', 'pids')) {
|
||||
$isAdd = true;
|
||||
$table->string('pids', 255)->nullable()->default('')->after('id')->comment('上级ID递归');
|
||||
}
|
||||
});
|
||||
if ($isAdd) {
|
||||
// 更新数据
|
||||
\App\Models\File::where('pid', '>', 0)->chunkById(100, function ($lists) {
|
||||
/** @var \App\Models\File $item */
|
||||
foreach ($lists as $item) {
|
||||
$item->saveBeforePids();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('files', function (Blueprint $table) {
|
||||
$table->dropColumn("pids");
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -326,5 +326,12 @@ class FilesTableSeeder extends Seeder
|
||||
$content->save();
|
||||
}
|
||||
});
|
||||
|
||||
File::where('pid', '>', 0)->chunkById(100, function ($lists) {
|
||||
/** @var File $item */
|
||||
foreach ($lists as $item) {
|
||||
$item->saveBeforePids();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,9 +51,9 @@
|
||||
</template>
|
||||
<div v-if="loadIng > 0" class="nav-load"><Loading/></div>
|
||||
<div class="flex-full"></div>
|
||||
<div :class="['switch-button', tableMode ? 'table' : '']" @click="tableMode=!tableMode">
|
||||
<div><i class="taskfont"></i></div>
|
||||
<div><i class="taskfont"></i></div>
|
||||
<div :class="['switch-button', tableMode]">
|
||||
<div @click="tableMode='table'"><i class="taskfont"></i></div>
|
||||
<div @click="tableMode='block'"><i class="taskfont"></i></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -62,22 +62,7 @@
|
||||
@drop.prevent="filePasteDrag($event, 'drag')"
|
||||
@dragover.prevent="fileDragOver(true, $event)"
|
||||
@dragleave.prevent="fileDragOver(false, $event)">
|
||||
<div v-if="tableMode" class="file-table" @contextmenu.prevent="handleRightClick">
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data="fileList"
|
||||
:height="tableHeight"
|
||||
:no-data-text="$L('没有任何文件')"
|
||||
@on-cell-click="clickRow"
|
||||
@on-contextmenu="handleContextMenu"
|
||||
@on-select="handleTableSelect"
|
||||
@on-select-cancel="handleTableSelect"
|
||||
@on-select-all-cancel="handleTableSelect"
|
||||
@on-select-all="handleTableSelect"
|
||||
context-menu
|
||||
stripe/>
|
||||
</div>
|
||||
<template v-else>
|
||||
<template v-if="tableMode === 'block'">
|
||||
<div v-if="fileList.length == 0 && loadIng == 0" class="file-no" @contextmenu.prevent="handleRightClick">
|
||||
<i class="taskfont"></i>
|
||||
<p>{{$L('没有任何文件')}}</p>
|
||||
@ -129,6 +114,21 @@
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
<div v-else class="file-table" @contextmenu.prevent="handleRightClick">
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data="fileList"
|
||||
:height="tableHeight"
|
||||
:no-data-text="$L('没有任何文件')"
|
||||
@on-cell-click="clickRow"
|
||||
@on-contextmenu="handleContextMenu"
|
||||
@on-select="handleTableSelect"
|
||||
@on-select-cancel="handleTableSelect"
|
||||
@on-select-all-cancel="handleTableSelect"
|
||||
@on-select-all="handleTableSelect"
|
||||
context-menu
|
||||
stripe/>
|
||||
</div>
|
||||
<div v-if="dialogDrag" class="drag-over" @click="dialogDrag=false">
|
||||
<div class="drag-text">{{$L('拖动到这里发送')}}</div>
|
||||
</div>
|
||||
@ -426,7 +426,7 @@ export default {
|
||||
],
|
||||
|
||||
tableHeight: 500,
|
||||
tableMode: $A.getStorageBoolean("fileTableMode"),
|
||||
tableMode: $A.getStorageString("fileTableMode"),
|
||||
columns: [],
|
||||
|
||||
shareShow: false,
|
||||
|
||||
9
resources/assets/sass/pages/page-file.scss
vendored
9
resources/assets/sass/pages/page-file.scss
vendored
@ -223,7 +223,7 @@
|
||||
color: $primary-color;
|
||||
}
|
||||
}
|
||||
&.table {
|
||||
&.block {
|
||||
&:before {
|
||||
left: 50%;
|
||||
}
|
||||
@ -308,6 +308,13 @@
|
||||
margin-right: 8px;
|
||||
}
|
||||
}
|
||||
.common-avatar {
|
||||
.el-avatar {
|
||||
> span {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
}
|
||||
.permission {
|
||||
padding-left: 6px;
|
||||
font-size: 13px;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user