Skip to content

Commit f8efbcd

Browse files
committed
feat: configurable inactive station limit
1 parent 3dcfe4c commit f8efbcd

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

config/custom-environment-variables.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@
332332
"__name": "API_STATION_UPDATE_LIMIT",
333333
"__format": "number"
334334
},
335+
"stationInactiveLimitDays": {
336+
"__name": "API_STATION_INACTIVE_LIMIT_DAYS",
337+
"__format": "number"
338+
},
335339
"searchResultsLimit": {
336340
"__name": "API_SEARCH_RESULTS_LIMIT",
337341
"__format": "number"
@@ -2331,4 +2335,4 @@
23312335
}
23322336
}
23332337
}
2334-
}
2338+
}

config/default.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
"portalUpdateLimit": 30,
118118
"weatherCellLimit": 3,
119119
"stationUpdateLimit": 9,
120+
"stationInactiveLimitDays": 120,
120121
"searchResultsLimit": 15,
121122
"searchSoftKmLimit": 10,
122123
"searchHardKmLimit": 100,

server/src/models/Station.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class Station extends Model {
2222
*/
2323
static async getAll(perms, args, { isMad, hasStationedGmax }) {
2424
const { areaRestrictions } = perms
25-
const { stationUpdateLimit } = config.getSafe('api')
25+
const { stationUpdateLimit, stationInactiveLimitDays } =
26+
config.getSafe('api')
2627
const {
2728
onlyAreas,
2829
onlyAllStations,
@@ -55,7 +56,9 @@ class Station extends Model {
5556
maxLon: args.maxLon,
5657
},
5758
})
58-
const activeCutoff = Date.now() / 1000 - stationUpdateLimit * 60 * 60
59+
const now = Date.now() / 1000
60+
const activeCutoff = now - stationUpdateLimit * 60 * 60
61+
const inactiveCutoff = now - stationInactiveLimitDays * 24 * 60 * 60
5962

6063
if (onlyInactiveStations) {
6164
query.andWhere((builder) => {
@@ -65,7 +68,11 @@ class Station extends Model {
6568
.where('end_time', '>', ts)
6669
.andWhere('updated', '>', activeCutoff),
6770
)
68-
.orWhere('end_time', '<=', ts)
71+
.orWhere((inactive) =>
72+
inactive
73+
.where('end_time', '<=', ts)
74+
.andWhere('updated', '>', inactiveCutoff),
75+
)
6976
})
7077
} else {
7178
query.andWhere('end_time', '>', ts).andWhere('updated', '>', activeCutoff)

0 commit comments

Comments
 (0)