Skip to content

Commit

Permalink
perf: 上传文件夹
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Feb 9, 2022
1 parent e89ff02 commit a6ba59e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions app/Http/Controllers/Api/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,11 @@ public function content__upload()
}
//
$dirs = explode("/", $webkitRelativePath);
AbstractModel::transaction(function() use ($user, $userid, $dirs, &$pid) {
while (count($dirs) > 1) {
$dirName = array_shift($dirs);
if ($dirName) {
while (count($dirs) > 1) {
$dirName = array_shift($dirs);
if ($dirName) {
$pushMsg = [];
AbstractModel::transaction(function () use ($dirName, $user, $userid, &$pid, &$pushMsg) {
$dirRow = File::wherePid($pid)->whereType('folder')->whereName($dirName)->lockForUpdate()->first();
if (empty($dirRow)) {
$dirRow = File::createInstance([
Expand All @@ -578,17 +579,19 @@ public function content__upload()
'created_id' => $user->userid,
]);
if ($dirRow->save()) {
$tmpRow = File::find($dirRow->id);
$tmpRow->pushMsg('add', $tmpRow);
$pushMsg[] = File::find($dirRow->id);
}
}
if (empty($dirRow)) {
throw new ApiException('创建文件夹失败');
}
$pid = $dirRow->id;
});
foreach ($pushMsg as $tmpRow) {
$tmpRow->pushMsg('add', $tmpRow);
}
}
});
}
//
$path = 'uploads/file/' . date("Ym") . '/u' . $user->userid . '/';
$data = Base::upload([
Expand Down

0 comments on commit a6ba59e

Please sign in to comment.