Skip to content

Conversation

@ldechamps
Copy link
Contributor

Change description

Following the same pattern as MAX_RELATIONAL_DEPTH, we implemented MAX_ITEMS_PER_QUERY.
By default, MAX_ITEMS_PER_QUERY is set to 1000 and can be set to -1 to remove the limitations.
The -1 limit is still used in the queries but is capped by MAX_ITEMS_PER_QUERY.

Type of change

  • Bug fix (fixes an issue)
  • New feature (adds functionality)

Related issues

Fix #172

Checklists

Development

  • Lint rules pass locally
  • Application changes have been tested thoroughly
  • Automated tests covering modified code pass

Security

  • Security impact of change has been considered
  • Code follows company security practices and guidelines

Network

  • Changes to network configurations have been reviewed
  • Any newly exposed public endpoints or data have gone through security review

Code review

  • Pull request has a descriptive title and context useful to a reviewer. Screenshots or screencasts are attached as necessary
  • reviewers assigned
  • Pull request linked to task tracker where applicable

'MAX_BATCH_MUTATION',
'LOGGER_.+',
'ROBOTS_TXT',
'MAX_RELATIONAL_DEPTH',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not present in the rest of the code ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It already existed; it just wasn’t present here like all environment variables. Here’s an example of a call:
const maxRelationalDepth = Number(env['MAX_RELATIONAL_DEPTH']) > 2 ? Number(env['MAX_RELATIONAL_DEPTH']) : 2;

let limit = sanitizeLimit(rawQuery['limit']);

if (typeof limit === 'number') {
const maxItemsPerQuery = Number(env['MAX_ITEMS_PER_QUERY']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

env already has a functionality to format env value.
It uses either typeMap or a type prefix in the env variable.
Would it be possible to use this instead ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I will look into that. I based myself on the existing practices on the following line:
const maxRelationalDepth = Number(env['MAX_RELATIONAL_DEPTH']) > 2 ? Number(env['MAX_RELATIONAL_DEPTH']) : 2;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be automatically converted with:
if (
String(value).startsWith('0') === false &&
isNaN(value) === false &&
value.length > 0 &&
value <= Number.MAX_SAFE_INTEGER
) {
env[key] = Number(value);
continue;
}

It could be enforced by adding it in typeMap.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then we can remove the Number(...) constructor ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's done

if (typeof limit === 'number') {
const maxItemsPerQuery = Number(env['MAX_ITEMS_PER_QUERY']);

if (maxItemsPerQuery !== -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxItemsPerQuery !== -1 && limit === -1 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

function validateLimit(limit: any) {
const maxItemsPerQuery = Number(env['MAX_ITEMS_PER_QUERY']) || 1000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be manage by the getEnv and env definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, moreover, I initialized it in defaults.

function validateLimit(limit: any) {
const maxItemsPerQuery = Number(env['MAX_ITEMS_PER_QUERY']) || 1000;

if (limit !== -1 && maxItemsPerQuery !== -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxItemsPerQuery !== -1 is sufficient here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, that was the initial test before adding the sanitize.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants