|
@@ -251,11 +251,27 @@ class FolderController extends Controller
|
|
|
->where($objectWhere)
|
|
|
->when($folderId, fn($query) => $query->where("parent_id", $folderId))
|
|
|
->when(! $folderId, fn($query) => $query->where("parent_id", 0))
|
|
|
- ->get(['id', 'name'])->each(function ($folders)use ($folderId){
|
|
|
- $folderCount=Folder::query()->where('parent_id',$folders->id)->count();
|
|
|
- $filesCount=File::query()->where('folder_id',$folderId>0?$folders->id:$folderId)->where("is_latest_version", 1)->count();
|
|
|
- $folders->itemCount=$folderCount+$filesCount;
|
|
|
- });
|
|
|
+ ->get(['id', 'name']);
|
|
|
+
|
|
|
+ $sonFolderCount=Folder::query()
|
|
|
+ ->where($objectWhere)
|
|
|
+ ->whereIn('parent_id',$folders->pluck('id'))
|
|
|
+ ->selectRaw("count(*) as cut, parent_id")
|
|
|
+ ->groupBy("parent_id")
|
|
|
+ ->pluck("cut", "parent_id");
|
|
|
+
|
|
|
+ $sonFileCount=File::query()
|
|
|
+ ->where($objectWhere)
|
|
|
+ ->whereIn('folder_id',$folders->pluck('id'))
|
|
|
+ ->selectRaw("count(*) as cut, folder_id")
|
|
|
+ ->groupBy("folder_id")
|
|
|
+ ->pluck("cut", "folder_id");
|
|
|
+
|
|
|
+ $folders = $folders->map(function (Folder $folder) use ($sonFolderCount,$sonFileCount) {
|
|
|
+ $folder->itemCount =$sonFolderCount->get($folder->id, 0)+$sonFileCount->get($folder->id, 0);
|
|
|
+ return $folder;
|
|
|
+ });
|
|
|
+
|
|
|
|
|
|
|
|
|
$files = File::query()->where($objectWhere)
|