Skip to content

Commit

Permalink
Max skip limit
Browse files Browse the repository at this point in the history
  • Loading branch information
orange1337 committed Feb 19, 2019
1 parent a8608a7 commit bc2d55e
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions api/v1.api.history.js
Expand Up @@ -309,18 +309,21 @@ module.exports = (app, DB, swaggerSpec, ObjectId) => {
if (sort !== -1 && sort !== 1){
return res.status(401).send(`Sort param must be 1 or -1`);
}
if (skip > MAX_SKIP){
return res.status(500).send("Large skip for account! Max skip per request " + MAX_SKIP);
}

let accountName = String(req.params.account);
let action = String(req.params.action);
let counter = Number(req.query.counter);
let actionsNamesArr = (typeof req.query.filter === "string") ? req.query.filter.split(","): null;

if (latencySkip[accountName] > +new Date()){
/*if (latencySkip[accountName] > +new Date()){
return res.status(500).send("Large skip for account, please wait until previous request will end! Max skip per request " + MAX_SKIP);
}
if (!latencySkip[accountName] && skip > MAX_SKIP){
latencySkip[accountName] = +new Date() + 60000;
}
}*/

let query = { $or: [
{"act.account": accountName},
Expand Down Expand Up @@ -358,9 +361,9 @@ module.exports = (app, DB, swaggerSpec, ObjectId) => {
console.error(err);
return res.status(500).end();
}
if (latencySkip[accountName] && skip > MAX_SKIP){
/*if (latencySkip[accountName] && skip > MAX_SKIP){
delete latencySkip[accountName];
}
}*/
res.json(result)
});
}
Expand All @@ -373,7 +376,7 @@ module.exports = (app, DB, swaggerSpec, ObjectId) => {
let accountName = String(req.body.account_name);
let action = String(req.body.action_name);
let counter = Number(req.body.counter);

let query = { $or: [
{"act.account": accountName},
{"act.data.receiver": accountName},
Expand Down Expand Up @@ -404,13 +407,16 @@ module.exports = (app, DB, swaggerSpec, ObjectId) => {
if (sort !== -1 && sort !== 1){
return res.status(401).send(`Sort param must be 1 or -1`);
}
if (skip > MAX_SKIP){
return res.status(500).send("Large skip for account! Max skip per request " + MAX_SKIP);
}

if (latencySkip[accountName] > +new Date()){
/*if (latencySkip[accountName] > +new Date()){
return res.status(500).send("Large skip for account, please wait until previous request will end! Max skip per request " + MAX_SKIP);
}
if (!latencySkip[accountName] && skip > MAX_SKIP){
latencySkip[accountName] = +new Date() + 60000;
}
}*/

let parallelObject = {
actions: (callback) => {
Expand All @@ -429,9 +435,9 @@ module.exports = (app, DB, swaggerSpec, ObjectId) => {
console.error(err);
return res.status(500).end();
}
if (latencySkip[accountName] && skip > MAX_SKIP){
/*if (latencySkip[accountName] && skip > MAX_SKIP){
delete latencySkip[accountName];
}
}*/
res.json(result)
});
}
Expand Down

0 comments on commit bc2d55e

Please sign in to comment.