Skip to content

Commit 1818850

Browse files
committed
Fixed sparse fieldsets array handling and one small aggregate data error
1 parent 70ff641 commit 1818850

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/inc/apiv2/common/AbstractBaseAPI.class.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,11 @@ protected function obj2Resource(object $obj, array $expandResult = [], array $sp
561561

562562
$attributes = [];
563563
$relationships = [];
564+
565+
$sparseFieldsetsForObj = null;
566+
if (is_array($sparseFieldsets) && array_key_exists($this->getObjectTypeName($obj), $sparseFieldsets)) {
567+
$sparseFieldsetsForObj = explode(",", $sparseFieldsets[$this->getObjectTypeName($obj)]);
568+
}
564569

565570
/* Collect attributes */
566571
foreach ($features as $name => $feature) {
@@ -571,7 +576,7 @@ protected function obj2Resource(object $obj, array $expandResult = [], array $sp
571576
}
572577

573578
// If sparse fieldsets (https://jsonapi.org/format/#fetching-sparse-fieldsets) is used, return only the requested data
574-
if (is_array($sparseFieldsets) && array_key_exists($this->getObjectTypeName($obj), $sparseFieldsets) && !in_array($feature['alias'], $sparseFieldsets[$this->getObjectTypeName($obj)])) {
579+
if (is_array($sparseFieldsetsForObj) && !in_array($feature['alias'], $sparseFieldsetsForObj)) {
575580
continue;
576581
}
577582

src/inc/apiv2/model/tasks.routes.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ static function aggregateData(object $object, array $aggregateFieldsets = null):
166166
$keyspaceProgress = $object->getKeyspaceProgress();
167167

168168
if(is_null($aggregateFieldsets) || (is_array($aggregateFieldsets) && array_key_exists('task', $aggregateFieldsets))) {
169+
$aggregateFieldsets['task'] = explode(",", $aggregateFieldsets['task']);
170+
169171
if(is_null($aggregateFieldsets) || in_array("dispatched", $aggregateFieldsets['task'])) {
170172
$aggregatedData["dispatched"] = Util::showperc($keyspaceProgress, $keyspace);
171173
}
@@ -174,11 +176,11 @@ static function aggregateData(object $object, array $aggregateFieldsets = null):
174176
$aggregatedData["searched"] = Util::showperc(TaskUtils::getTaskProgress($object), $keyspace);
175177
}
176178

179+
$activeAgents = [];
177180
if(is_null($aggregateFieldsets) || in_array("activeAgents", $aggregateFieldsets['task'])) {
178181
$qF = new QueryFilter(Chunk::TASK_ID, $object->getId(), "=");
179182
$chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]);
180183

181-
$activeAgents = [];
182184
foreach ($chunks as $chunk) {
183185
if (time() - max($chunk->getSolveTime(), $chunk->getDispatchTime()) < SConfig::getInstance()->getVal(DConfig::CHUNK_TIMEOUT) && $chunk->getProgress() < 10000) {
184186
$activeAgents[$chunk->getAgentId()] = true;

0 commit comments

Comments
 (0)