@@ -160,36 +160,47 @@ protected function createObject(array $data): int {
160160 return $ task ->getId ();
161161 }
162162
163- //TODO make aggregate data queryable and not included by default
164- static function aggregateData (object $ object ): array {
163+ //TODO make aggregate data queryable
164+ static function aggregateData (object $ object , array $ sparseFieldsets = null ): array {
165+ $ aggregatedData = [];
165166 $ keyspace = $ object ->getKeyspace ();
166167 $ keyspaceProgress = $ object ->getKeyspaceProgress ();
167168
168- $ aggregatedData ["dispatched " ] = Util::showperc ($ keyspaceProgress , $ keyspace );
169- $ aggregatedData ["searched " ] = Util::showperc (TaskUtils::getTaskProgress ($ object ), $ keyspace );
170-
171- $ qF = new QueryFilter (Chunk::TASK_ID , $ object ->getId (), "= " );
172- $ chunks = Factory::getChunkFactory ()->filter ([Factory::FILTER => $ qF ]);
173-
174- $ activeAgents = [];
175- foreach ($ chunks as $ chunk ) {
176- if (time () - max ($ chunk ->getSolveTime (), $ chunk ->getDispatchTime ()) < SConfig::getInstance ()->getVal (DConfig::CHUNK_TIMEOUT ) && $ chunk ->getProgress () < 10000 ) {
177- $ activeAgents [$ chunk ->getAgentId ()] = true ;
178- }
169+ if (is_array ($ sparseFieldsets ) && array_key_exists ('task ' , $ sparseFieldsets ) && in_array ("dispatched " , $ sparseFieldsets ['task ' ]) ) {
170+ $ aggregatedData ["dispatched " ] = Util::showperc ($ keyspaceProgress , $ keyspace );
179171 }
180-
181- //status 1 is running, 2 is idle and 3 is completed
182- $ status = 2 ;
183- if ($ keyspaceProgress >= $ keyspace && $ keyspaceProgress > 0 ) {
184- $ status = 3 ;
172+
173+ if (is_array ($ sparseFieldsets ) && array_key_exists ('task ' , $ sparseFieldsets ) && in_array ("searched " , $ sparseFieldsets ['task ' ]) ) {
174+ $ aggregatedData ["searched " ] = Util::showperc (TaskUtils::getTaskProgress ($ object ), $ keyspace );
175+ }
176+
177+ if (is_array ($ sparseFieldsets ) && array_key_exists ('task ' , $ sparseFieldsets ) && in_array ("activeAgents " , $ sparseFieldsets ['task ' ]) ) {
178+ $ qF = new QueryFilter (Chunk::TASK_ID , $ object ->getId (), "= " );
179+ $ chunks = Factory::getChunkFactory ()->filter ([Factory::FILTER => $ qF ]);
180+
181+ $ activeAgents = [];
182+ foreach ($ chunks as $ chunk ) {
183+ if (time () - max ($ chunk ->getSolveTime (), $ chunk ->getDispatchTime ()) < SConfig::getInstance ()->getVal (DConfig::CHUNK_TIMEOUT ) && $ chunk ->getProgress () < 10000 ) {
184+ $ activeAgents [$ chunk ->getAgentId ()] = true ;
185+ }
186+ }
187+
188+ $ aggregatedData ["activeAgents " ] = array_keys ($ activeAgents );
185189 }
186- elseif (count ($ activeAgents ) > 0 ) {
187- $ status = 1 ;
190+
191+ if (is_array ($ sparseFieldsets ) && array_key_exists ('task ' , $ sparseFieldsets ) && in_array ("searched " , $ sparseFieldsets ['task ' ]) ) {
192+ //status 1 is running, 2 is idle and 3 is completed
193+ $ status = 2 ;
194+ if ($ keyspaceProgress >= $ keyspace && $ keyspaceProgress > 0 ) {
195+ $ status = 3 ;
196+ }
197+ elseif (count ($ activeAgents ) > 0 ) {
198+ $ status = 1 ;
199+ }
200+
201+ $ aggregatedData ["status " ] = $ status ;
188202 }
189203
190- $ aggregatedData ["activeAgents " ] = array_keys ($ activeAgents );
191- $ aggregatedData ["status " ] = $ status ;
192-
193204 return $ aggregatedData ;
194205 }
195206
0 commit comments