Skip to content

Commit

Permalink
fix: add performance measure to limit how many tracking queries can g…
Browse files Browse the repository at this point in the history
…et executed at once
  • Loading branch information
niekcandaele committed Aug 6, 2024
1 parent 85c68db commit 8775d96
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion api/controllers/tracking-info/get-tracking-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,27 @@ module.exports = {
},


exits: {},
exits: {
badRequest: {
responseType: 'badRequest'
},
},


fn: async function (inputs, exits) {
const lastTrackingQuery = await sails.helpers.redis.get(`server:${inputs.serverId}:trackingQuery`);

if (lastTrackingQuery) {
const lastQuery = new Date(JSON.parse(lastTrackingQuery));
const now = new Date();

// If last query is less than 10 seconds ago, return an error
if (now - lastQuery < 10000) {
return exits.badRequest("You can only query tracking data every 10 seconds");
}
}

await sails.helpers.redis.set(`server:${inputs.serverId}:trackingQuery`, JSON.stringify(new Date().toISOString()), true, 10);

let startDate = new Date();

Expand Down

0 comments on commit 8775d96

Please sign in to comment.