Skip to content

Commit

Permalink
Add maxDaysAgo limit to queries on import and export orders for a system
Browse files Browse the repository at this point in the history
Query performance is actually fine with this being unlimited but returning really old data for imports can result in _very_ large payloads, sometimes 5 MB of JSON data for single system, filled with mostly old data that isn't really relevant.

This change will improve relevance, performance and reduce network load but at the cost of slightly less useful data.

I may be inclined to bump up this threshold to 90 days if 30 proves too limiting - which wil be partly dependant on the amount of data coming through EDDN (i.e. how active players are).
  • Loading branch information
iaincollins committed Nov 9, 2024
1 parent 3daded1 commit a86c48e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ although the approximate distance to the main star for each station is
displayed (when known) it is not taken into account.

* As of API version `3.0.0` the commodity `import` and `export` endpoints
support a `maxDaysAgo` option that defaults to `90` days. This filters out data
older than 90 days from results by default, which makes results more relevant
support a `maxDaysAgo` option that defaults to `30` days. This filters out data
older than 30 days from results by default, which makes results more relevant
and improves response times. You can still request to include older data by
explicitly specifying a greater value. Records are updated when newer
information is submitted, but older entries never expire.
Expand Down Expand Up @@ -143,7 +143,7 @@ e.g. https://api.ardent-industry.com/v1/commodity/name/gold/imports
* minVolume (int); default 1
* minPrice (int); default 1
* fleetCarriers (bool); default null
* maxDaysAgo (int); default 90
* maxDaysAgo (int); default 30

#### Get exporters for a commodity

Expand All @@ -159,7 +159,7 @@ e.g. https://api.ardent-industry.com/v1/commodity/name/gold/exports
* minVolume (int); default 1
* maxPrice (int); default null
* fleetCarriers (bool); default null
* maxDaysAgo (int); default 90
* maxDaysAgo (int); default 30

#### Get trade reports for a commodity

Expand Down Expand Up @@ -223,6 +223,7 @@ e.g. https://api.ardent-industry.com/v1/system/name/Sol/commodities/imports
* minVolume (int); default 1
* minPrice (int); default 1
* fleetCarriers (bool); default null
* maxDaysAgo (int); default 30

#### Get commodities exported by a system

Expand All @@ -238,6 +239,7 @@ e.g. https://api.ardent-industry.com/v1/system/name/Sol/commodities/exports
* minVolume (int); default 1
* maxPrice (int); default null
* fleetCarriers (bool); default null
* maxDaysAgo (int); default 30

#### Get trade data for a commodity in a system

Expand All @@ -263,7 +265,7 @@ e.g. https://api.ardent-industry.com/v1/system/name/Sol/commodity/name/gold/near
* minPrice (int); default 1
* fleetCarriers (bool); default null
* maxDistance (int); default 100, max 500
* maxDaysAgo (int); default 90
* maxDaysAgo (int); default 30

#### Get a list of nearby exporters of a commodity

Expand All @@ -281,7 +283,7 @@ e.g. https://api.ardent-industry.com/v1/system/name/Sol/commodity/name/gold/near
* maxPrice (int); default null
* fleetCarriers (bool); default null
* maxDistance (int); default 100, max 500
* maxDaysAgo (int); default 90
* maxDaysAgo (int); default 30

#### Get trade data for a commodity in a specific market

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ardent-api",
"version": "4.6.0",
"version": "4.7.0",
"description": "Ardent API provides access to data submitted to EDDN",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 8 additions & 4 deletions router/api/systems.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ module.exports = (router) => {
const {
minVolume = 1,
minPrice = 1,
fleetCarriers = null
fleetCarriers = null,
maxDaysAgo = DEFAULT_MAX_RESULTS_AGE
} = ctx.query

// Validate system name
Expand All @@ -234,7 +235,8 @@ module.exports = (router) => {

const filters = [
`AND (c.demand >= ${parseInt(minVolume)} OR c.demand = 0)`, // Zero is infinite demand
`AND c.sellPrice >= ${parseInt(minPrice)}`
`AND c.sellPrice >= ${parseInt(minPrice)}`,
`AND c.updatedAtDay > '${getISOTimestamp(`-${maxDaysAgo}`).split('T')[0]}'`
]

if (paramAsBoolean(fleetCarriers) !== null) {
Expand Down Expand Up @@ -279,15 +281,17 @@ module.exports = (router) => {
const {
minVolume = 1,
maxPrice = null,
fleetCarriers = null
fleetCarriers = null,
maxDaysAgo = DEFAULT_MAX_RESULTS_AGE
} = ctx.query

// Validate system name
const system = await getSystemByName(systemName)
if (!system) return NotFoundResponse(ctx, 'System not found')

const filters = [
`AND c.stock >= ${parseInt(minVolume)}`
`AND c.stock >= ${parseInt(minVolume)}`,
`AND c.updatedAtDay > '${getISOTimestamp(`-${maxDaysAgo}`).split('T')[0]}'`
]

if (maxPrice !== null) { filters.push(`AND c.buyPrice <= ${parseInt(maxPrice)}`) }
Expand Down

0 comments on commit a86c48e

Please sign in to comment.