Safe Haskell | None |
---|---|
Language | Haskell2010 |
- class RateLimit action entity | action -> entity where
- rateLimit :: action -> (Int, Int)
- convertAction :: action -> UTCTime -> entity
- timeConstructor :: action -> EntityField entity UTCTime
- deleteFilters :: action -> [Filter entity]
- rateLimitFilters :: action -> [Filter entity]
- numberOfRemainingActions :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO Int
- canPerformAction :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO Bool
- recordAction :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO ()
- deleteRecordedAction :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO ()
- cleanOldActions :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO ()
Documentation
class RateLimit action entity | action -> entity where Source
rateLimit :: action -> (Int, Int) Source
Number of actions allowed in the defined period. Period is easured in seconds.
convertAction :: action -> UTCTime -> entity Source
Convert a given action and time into an entity.
timeConstructor :: action -> EntityField entity UTCTime Source
Return the field for the time constructor in the entity.
deleteFilters :: action -> [Filter entity] Source
Filter to delete the records of a specific action.
rateLimitFilters :: action -> [Filter entity] Source
Optionally add additional filters for database queries. The default is `[]`. You probably only need this if multiple rate limiters use the same entity.
numberOfRemainingActions :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO Int Source
Returns the number of actions remaining for the current period.
canPerformAction :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO Bool Source
Determines whether an actions can be performed.
recordAction :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO () Source
Record when an action occurs.
deleteRecordedAction :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO () Source
Delete the recorded logs of an action.
cleanOldActions :: (RateLimit action entity, PersistEntityBackend entity ~ YesodPersistBackend site, YesodPersist site, PersistEntity entity, PersistQuery (YesodPersistBackend site)) => action -> HandlerT site IO () Source
Periodically call this function to delete old actions that are past the rate limit period. A nonsensical action can be used as only the rate limit period will be used.