@@ -950,7 +950,7 @@ private function handleEntityRelationReturnComplexData(&$newReturnData, $type =
950950 $ this ->unfoldEntityRelationConfig ($ relationUnfold , $ maxDepthRelationConfig );
951951
952952 // 查询关联数据
953- $ middleEntityData = $ this ->getFilterMiddleData ('entity ' , ['id ' => ['IN ' , join (', ' , $ this ->queryModulePrimaryKeyIds )]], ' id,entity_id ' );
953+ $ middleEntityData = $ this ->getModelObj ('entity ' )-> field ( ' id,entity_id ' )-> where ( ['id ' => ['IN ' , join (', ' , $ this ->queryModulePrimaryKeyIds )]])-> select ( );
954954
955955 $ middleRelationIds = array_column ($ middleEntityData , 'entity_id ' );
956956
@@ -979,10 +979,10 @@ private function handleEntityRelationReturnComplexData(&$newReturnData, $type =
979979
980980 $ this ->handleQueryModuleCustomFields ($ fields , $ relationUnfold [$ i ]['belong_module ' ]);
981981
982- $ entityData = $ this ->getFilterMiddleData ('entity ' , [
982+ $ entityData = $ this ->getModelObj ('entity ' )-> field ( join ( ' , ' , $ fields ))-> where ( [
983983 'id ' => ['IN ' , join (', ' , $ middleRelationIds )],
984984 'module_id ' => $ relationUnfold [$ i ]['src_module_id ' ],
985- ], join ( ' , ' , $ fields ) );
985+ ])-> select ( );
986986
987987
988988 if (!empty ($ entityData )) {
@@ -1661,6 +1661,15 @@ public function parserFilterModuleCustomFields($queryModuleList)
16611661 }
16621662 unset($ queryModuleIds );
16631663
1664+ // 优化,使用全局静态缓存
1665+ // $customFieldData = $this->getModelObj('field')->field('id,table,module_id,config')
1666+ // ->where([
1667+ // 'type' => 'custom',
1668+ // 'is_horizontal' => 0,
1669+ // 'module_id' => ['IN', join(',', $queryModuleIds)]
1670+ // ])
1671+ // ->select();
1672+
16641673 if (!empty ($ customFieldData )) {
16651674 foreach ($ customFieldData as $ customFieldItem ) {
16661675 $ customFieldItemConfig = json_decode ($ customFieldItem ['config ' ], true );
@@ -1679,6 +1688,7 @@ public function parserFilterModuleCustomFields($queryModuleList)
16791688 private function getRelationModuleCustomFields ($ modules )
16801689 {
16811690 $ relationModule = [];
1691+ //$entityModuleList = $this->getModelObj('module')->field('code')->where(['type' => 'entity'])->select();
16821692
16831693 foreach ($ modules as $ moduleKey => $ config ) {
16841694 if ($ config ['type ' ] !== 'horizontal ' ) {
@@ -1879,7 +1889,7 @@ private function parserFilterItemComplexValue($masterModuleCode, $itemModule, $s
18791889 */
18801890 private function parserFilterItemEntityTaskRelated (&$ filterData , $ masterModuleCode , $ itemModule , $ filter )
18811891 {
1882- $ selectData = $ this ->getFilterMiddleData ('entity ' , $ this ->formatFilterCondition ($ filter ), ' id ' );
1892+ $ selectData = $ this ->getModelObj ('entity ' )-> where ( $ this ->formatFilterCondition ($ filter ))-> select ( );
18831893 if (!empty ($ selectData )) {
18841894 $ ids = array_column ($ selectData , 'id ' );
18851895 $ idsString = join (', ' , $ ids );
@@ -2055,7 +2065,7 @@ private function parserFilterItemValue($masterModuleCode, $itemModule, $filter)
20552065 }
20562066 break ;
20572067 case 'direct ' :
2058- $ selectData = $ this ->getFilterMiddleData (get_module_table_name (Module::$ moduleDictData ['module_index_by_code ' ][$ itemModule ['module_code ' ]]), $ this ->formatFilterCondition ($ filter ));
2068+ $ selectData = $ this ->getModelObj (get_module_table_name (Module::$ moduleDictData ['module_index_by_code ' ][$ itemModule ['module_code ' ]]))-> where ( $ this ->formatFilterCondition ($ filter ))-> select ( );
20592069 if (!empty ($ selectData )) {
20602070 $ ids = array_column ($ selectData , 'id ' );
20612071 $ idsString = join (', ' , $ ids );
@@ -2087,7 +2097,7 @@ private function parserFilterItemValue($masterModuleCode, $itemModule, $filter)
20872097 "code " => $ itemModule ['module_code ' ]
20882098 ]);
20892099
2090- $ selectData = $ this ->getFilterMiddleData ($ tableName, $ this ->formatFilterCondition ($ filter ));
2100+ $ selectData = $ this ->getModelObj ($ tableName)-> where ( $ this ->formatFilterCondition ($ filter ))-> select ( );
20912101 if (!empty ($ selectData )) {
20922102 $ ids = array_column ($ selectData , 'id ' );
20932103 $ idsString = join (', ' , $ ids );
@@ -2921,23 +2931,6 @@ public function selectData($options = [], $needFormat = true)
29212931 }
29222932 }
29232933
2924- /**
2925- * 获取查询中间数据,单次关联id数量不能超过2000
2926- * @param $modelName
2927- * @param $filter
2928- * @param $fields
2929- * @return array|false|mixed|string
2930- * @throws \Exception
2931- */
2932- private function getFilterMiddleData ($ modelName , $ filter , $ fields = 'id ' )
2933- {
2934- $ count = $ this ->getModelObj ($ modelName )->where ($ filter )->cache (60 )->count ();
2935- if ($ count > 2000 ) {
2936- // 2000 条大约占用内存 2mb
2937- throw_strack_exception ('The associated table data exceeds 2000. ' , ErrorCode::RELATED_TABLE_DATA_EXCEEDS_2000 );
2938- }
2939- return $ this ->getModelObj ($ modelName )->field ($ fields )->where ($ filter )->select ();
2940- }
29412934
29422935 /**
29432936 * 获取字段数据源映射
0 commit comments