Skip to content

Commit

Permalink
perf: une façon différente de fournir le paramètre fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ocruze committed Nov 26, 2024
1 parent d6b2d89 commit f692dc9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/Controller/Entrepot/DatasheetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getDatasheetList(string $datastoreId): JsonResponse
{
$uploads = $this->uploadApiService->getAll($datastoreId, [
'sort' => 'lastEvent,desc',
'fields' => ['tags'],
'fields' => 'tags',
]);

$uploadDatasheetNames = array_map(function ($upload) {
Expand All @@ -55,7 +55,7 @@ public function getDatasheetList(string $datastoreId): JsonResponse

$storedDataList = $this->storedDataApiService->getAll($datastoreId, [
'sort' => 'lastEvent,desc',
'fields' => ['tags'],
'fields' => 'tags',
]);

$storedDataDatasheetNames = array_map(function ($storedData) {
Expand Down
13 changes: 5 additions & 8 deletions src/Services/EntrepotApi/StoredDataApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,11 @@ public function getAll(string $datastoreId, array $query = []): array
$query['sort'] = 'lastEvent,desc';
}

/*
* pour transformer "sort=lastEvent,desc&fields[0]=field1&fields[1]=field2" en "sort=lastEvent,desc&fields=field1&fields=field2"
* l'API entrepôt ignore le premier format
*/
$queryString = urldecode(http_build_query($query));
$queryString = preg_replace('/\[\d+\]/', '', $queryString);

return $this->requestAll("datastores/$datastoreId/stored_data?{$queryString}");
if (array_key_exists('fields', $query) && is_array($query['fields']) && !empty($query['fields'])) {
$query['fields'] = implode(',', $query['fields']);
}

return $this->requestAll("datastores/$datastoreId/stored_data", $query);
}

/**
Expand Down
13 changes: 5 additions & 8 deletions src/Services/EntrepotApi/UploadApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ public function getAll(string $datastoreId, array $query = []): array
$query['sort'] = 'lastEvent,desc';
}

/*
* pour transformer "sort=lastEvent,desc&fields[0]=field1&fields[1]=field2" en "sort=lastEvent,desc&fields=field1&fields=field2"
* l'API entrepôt ignore le premier format
*/
$queryString = urldecode(http_build_query($query));
$queryString = preg_replace('/\[\d+\]/', '', $queryString);

return $this->requestAll("datastores/$datastoreId/uploads?{$queryString}");
if (array_key_exists('fields', $query) && is_array($query['fields']) && !empty($query['fields'])) {
$query['fields'] = implode(',', $query['fields']);
}

return $this->requestAll("datastores/$datastoreId/uploads", $query);
}

/**
Expand Down

0 comments on commit f692dc9

Please sign in to comment.