packages feed

persistent-ratelimit 0.1.0.0 → 0.1.0.1

raw patch · 2 files changed

+12/−9 lines, 2 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Database.Persist.RateLimit: class RateLimit action entity | action -> entity where rateLimitFilters _ = []
+ Database.Persist.RateLimit: class RateLimit action entity | action -> entity where deleteFilters _ = []

Files

persistent-ratelimit.cabal view
@@ -10,7 +10,7 @@ -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:             0.1.0.0+version:             0.1.0.1  -- A short (one-line) description of the package. synopsis:            A library for rate limiting activities with a persistent backend. @@ -64,6 +64,9 @@      -- Directories containing source files.   hs-source-dirs:      src++  ghc-options:   -Wall -fwarn-tabs -fno-warn-orphans -fno-warn-type-defaults -fno-warn-name-shadowing+  -- -Werror       -- Base language which the package is written in.   default-language:    Haskell2010
src/Database/Persist/RateLimit.hs view
@@ -16,13 +16,13 @@     timeConstructor :: action -> EntityField entity UTCTime      -- | Filter to delete the records of a specific action. +    -- The default is `[]`. +    -- You probably only need this if multiple rate limiters use the same database entity.      deleteFilters :: action -> [Filter entity]+    deleteFilters _ = [] -    -- | Optionally add additional filters for database queries. -    -- The default is `[]`. -    -- You probably only need this if multiple rate limiters use the same entity. +    -- | Filters to specify an action for database queries.      rateLimitFilters :: action -> [Filter entity]-    rateLimitFilters _ = []  -- | Returns the number of actions remaining for the current period.  numberOfRemainingActions :: (RateLimit action entity, @@ -48,7 +48,7 @@         PersistQuery (YesodPersistBackend site)) =>      action -> HandlerT site IO Bool canPerformAction action = -    numberOfRemainingActions action >>= return . (> 0)+    fmap (> 0) $ numberOfRemainingActions action  -- | Record when an action occurs.  recordAction :: (RateLimit action entity,@@ -70,7 +70,7 @@         PersistQuery (YesodPersistBackend site)) =>      action -> HandlerT site IO () deleteRecordedAction action =-    let filters = deleteFilters action in+    let filters = rateLimitFilters action in     runDB $ deleteWhere filters  -- | Periodically call this function to delete old actions that are past the rate limit period. @@ -84,7 +84,7 @@ cleanOldActions action = do     let ( _, period) = rateLimit action     let timeConstr = timeConstructor action-    let filters = rateLimitFilters action+    let filters = deleteFilters action     now <- lift getCurrentTime     let timeBound = addUTCTime (fromIntegral $ negate period) now-    runDB $ deleteWhere filters+    runDB $ deleteWhere $ (timeConstr <. timeBound):filters