Skip to content

Commit

Permalink
added parameter to test function to allow it to get correct value.
Browse files Browse the repository at this point in the history
  • Loading branch information
zedmonds96 committed Dec 18, 2024
1 parent f88fc95 commit bbf189c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion modules/datastore/config/install/datastore.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ rows_limit: 500
purge_file: 1
purge_table: 1
triggering_properties: []
datastore_response_stream_max_age: 3600
datastore_response_stream_max_age: 3600
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ abstract class AbstractQueryController implements ContainerInjectionInterface {
* @var int
*/
protected const DEFAULT_ROWS_LIMIT = 500;
protected const DEFAULT_RESPONSE_STREAM_MAX_AGE = 3600;

/**
* Api constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(QueryService $queryService, DatasetInfo $datasetInfo
// because datasets can be very large. However, we do want CDNs to be able
// to cache the CSV stream for a reasonable amount of time.
$config = $configFactory->get('datastore.settings');
$this->cacheMaxAge = $config->get('response_stream_max_age') ?? 3600;
$this->cacheMaxAge = $config->get('response_stream_max_age') ?: self::DEFAULT_RESPONSE_STREAM_MAX_AGE;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions modules/datastore/src/Form/DatastoreSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$form['response_stream_max_age'] = [
'#type' => 'number',
'#title' => $this->t('Response Stream Max-Age'),
'#default_value' => $this->config('datastore.settings')->get('response_stream_max_age'),
'#default_value' => $this->config('datastore.settings')->get('response_stream_max_age') ?: QueryController::DEFAULT_RESPONSE_STREAM_MAX_AGE,
'#min' => 0,
'#description' => $this->t('Set the cache max-age for streaming CSV responses, in seconds. Default: 3600 (1 hour).'),
];
Expand All @@ -95,7 +95,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('datastore.settings')
->set('rows_limit', $form_state->getValue('rows_limit') ?: QueryController::DEFAULT_ROWS_LIMIT)
->set('response_stream_max_age', $form_state->getValue('response_stream_max_age') ?: 3600)
->set('response_stream_max_age', $form_state->getValue('response_stream_max_age') ?: QueryController::DEFAULT_RESPONSE_STREAM_MAX_AGE)
->set('triggering_properties', $form_state->getValue('triggering_properties'))
->save();
parent::submitForm($form, $form_state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ public function testStreamedQueryJson() {
public function testStreamedLimit() {
$queryLimit = 75;
$pageLimit = 50;
$responseStreamMaxAge = 3600;
$data = json_encode([
"resources" => [
[
Expand All @@ -230,7 +231,7 @@ public function testStreamedLimit() {
"limit" => $queryLimit,
]);
// Set the row limit to 50 even though we're requesting 1000.
$container = $this->getQueryContainer($pageLimit);
$container = $this->getQueryContainer($pageLimit, $responseStreamMaxAge);
$downloadController = QueryDownloadController::create($container);
$request = $this->mockRequest($data);
ob_start([self::class, 'getBuffer']);
Expand Down Expand Up @@ -346,7 +347,7 @@ public function testStreamedBadSchema() {
* @return \MockChain\Chain
* MockChain chain object.
*/
private function getQueryContainer(int $rowLimit) {
private function getQueryContainer(int $rowLimit, int $responseStreamMaxAge) {
$options = (new Options())
->add("dkan.metastore.storage", DataFactory::class)
->add("dkan.datastore.service", DatastoreService::class)
Expand Down Expand Up @@ -413,9 +414,8 @@ private function getQueryContainer(int $rowLimit) {
->add(Query::class, "getQueryStorageMap", $storageMap)
->add(Query::class, 'getDatastoreService', DatastoreService::class)
->add(DatastoreService::class, 'getDataDictionaryFields', NULL)
->add(ImmutableConfig::class, 'get', function ($key) {
return $key === 'response_stream_max_age' ? 3600 : 50;
});
->add(ImmutableConfig::class, 'get', $rowLimit)
->add(ImmutableConfig::class, 'get', $responseStreamMaxAge);

return $chain->getMock();
}
Expand Down

0 comments on commit bbf189c

Please sign in to comment.