-
-
Save leblancmeneses/16274598b3a2da9c9566ef7e672a94be to your computer and use it in GitHub Desktop.
throttle messages to no more than one every 5,000 milliseconds, see http://jsfiddle.net/firebase/VBmA5/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type SharedWithInviteRequest { | |
........ | |
createdDate: RateLimiting | |
} | |
// in order to write a message, I must first make an entry in users/${uid}/rate_limiting/{feature} is Number | |
// additionally, that message must be within 500ms of now, which means I can't | |
// just re-use the same one over and over, thus, we've effectively required messages | |
// to be 5 seconds apart | |
type RateLimiting extends Number { | |
validate() { this >= now - 500 && this === root['users'][auth.uid]['rate_limiting']['xyz'] } | |
} | |
path /users/{$urlUserId} { | |
// the new value must be at least 5000 milliseconds after the last (no more than one message every five seconds) | |
// the new value must be before now (it will be since `now` is when it reaches the server unless I try to cheat) | |
/rate_limiting/{$throttling} is Number { | |
read() { isOwner($urlUserId) } | |
write() { isOwner($urlUserId) } | |
validate() { $throttling.test(/^(xyz)$/) && this === now && (prior(this) == null || this > prior(this)+5000) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment