-
Notifications
You must be signed in to change notification settings - Fork 246
Implemented sparse fieldsets support on the backend #1152 #1715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
d897121
cd61bff
70ff641
1818850
11bd146
cf0e5c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,36 +160,47 @@ protected function createObject(array $data): int { | |
| return $task->getId(); | ||
| } | ||
|
|
||
| //TODO make aggregate data queryable and not included by default | ||
| static function aggregateData(object $object): array { | ||
| //TODO make aggregate data queryable | ||
| static function aggregateData(object $object, array $sparseFieldsets = null): array { | ||
| $aggregatedData = []; | ||
| $keyspace = $object->getKeyspace(); | ||
| $keyspaceProgress = $object->getKeyspaceProgress(); | ||
|
|
||
| $aggregatedData["dispatched"] = Util::showperc($keyspaceProgress, $keyspace); | ||
| $aggregatedData["searched"] = Util::showperc(TaskUtils::getTaskProgress($object), $keyspace); | ||
|
|
||
| $qF = new QueryFilter(Chunk::TASK_ID, $object->getId(), "="); | ||
| $chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]); | ||
|
|
||
| $activeAgents = []; | ||
| foreach ($chunks as $chunk) { | ||
| if (time() - max($chunk->getSolveTime(), $chunk->getDispatchTime()) < SConfig::getInstance()->getVal(DConfig::CHUNK_TIMEOUT) && $chunk->getProgress() < 10000) { | ||
| $activeAgents[$chunk->getAgentId()] = true; | ||
| } | ||
| if(is_array($sparseFieldsets) && array_key_exists('task', $sparseFieldsets) && in_array("dispatched", $sparseFieldsets['task']) ) { | ||
| $aggregatedData["dispatched"] = Util::showperc($keyspaceProgress, $keyspace); | ||
| } | ||
|
|
||
| //status 1 is running, 2 is idle and 3 is completed | ||
| $status = 2; | ||
| if ($keyspaceProgress >= $keyspace && $keyspaceProgress > 0) { | ||
| $status = 3; | ||
|
|
||
| if(is_array($sparseFieldsets) && array_key_exists('task', $sparseFieldsets) && in_array("searched", $sparseFieldsets['task']) ) { | ||
|
||
| $aggregatedData["searched"] = Util::showperc(TaskUtils::getTaskProgress($object), $keyspace); | ||
| } | ||
|
|
||
| if(is_array($sparseFieldsets) && array_key_exists('task', $sparseFieldsets) && in_array("activeAgents", $sparseFieldsets['task']) ) { | ||
| $qF = new QueryFilter(Chunk::TASK_ID, $object->getId(), "="); | ||
| $chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]); | ||
|
|
||
| $activeAgents = []; | ||
| foreach ($chunks as $chunk) { | ||
| if (time() - max($chunk->getSolveTime(), $chunk->getDispatchTime()) < SConfig::getInstance()->getVal(DConfig::CHUNK_TIMEOUT) && $chunk->getProgress() < 10000) { | ||
| $activeAgents[$chunk->getAgentId()] = true; | ||
| } | ||
| } | ||
|
|
||
| $aggregatedData["activeAgents"] = array_keys($activeAgents); | ||
| } | ||
| elseif (count($activeAgents) > 0) { | ||
| $status = 1; | ||
|
|
||
| if(is_array($sparseFieldsets) && array_key_exists('task', $sparseFieldsets) && in_array("searched", $sparseFieldsets['task']) ) { | ||
|
||
| //status 1 is running, 2 is idle and 3 is completed | ||
| $status = 2; | ||
| if ($keyspaceProgress >= $keyspace && $keyspaceProgress > 0) { | ||
| $status = 3; | ||
| } | ||
| elseif (count($activeAgents) > 0) { | ||
| $status = 1; | ||
| } | ||
|
|
||
| $aggregatedData["status"] = $status; | ||
| } | ||
|
|
||
| $aggregatedData["activeAgents"] = array_keys($activeAgents); | ||
| $aggregatedData["status"] = $status; | ||
|
|
||
| return $aggregatedData; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to put the three if statements into a single if statement