Added rate limiting to heavy subscriptions

This commit is contained in:
Stefan Zermatten
2017-09-26 14:59:41 +02:00
parent 212986ac37
commit 4e96047e90
4 changed files with 20 additions and 5 deletions

View File

@@ -52,3 +52,4 @@ ongoworks:speakingurl
service-configuration@1.0.11
google-config-ui
dynamic-import
ddp-rate-limiter

View File

@@ -185,6 +185,7 @@ Schemas.Character = new SimpleSchema({
type: String,
defaultValue: "whitelist",
allowedValues: ["whitelist", "public"],
index: 1,
},
"settings.swapStatAndModifier": {type: Boolean, defaultValue: false},
"settings.exportFeatures": {type: Boolean, defaultValue: true},

View File

@@ -25,3 +25,10 @@ Meteor.publish("characterList", function(){
Parties.find({owner: userId}),
];
});
DDPRateLimiter.addRule({
name: "characterList",
type: "subscription",
userId(){ return true; },
connectionId(){ return true; },
}, 8, 5000);

View File

@@ -35,9 +35,16 @@ Meteor.publish("singleCharacter", function(characterId){
}
});
DDPRateLimiter.addRule({
name: "singleCharacter",
type: "subscription",
userId(){ return true; },
connectionId(){ return true; },
}, 8, 5000);
Meteor.publish("singleCharacterName", function(characterId){
userId = this.userId;
var char = Characters.findOne({
return Characters.find({
_id: characterId,
$or: [
{readers: userId},
@@ -45,8 +52,7 @@ Meteor.publish("singleCharacterName", function(characterId){
{owner: userId},
{"settings.viewPermission": "public"},
],
}, {
fields:{"name": 1}
});
if (char) {
return Characters.find(characterId, {fields:{"name": 1}});
}
});
});