2021-09-24 01:56:37 +03:00
|
|
|
-- | graphql-engine used to have a query plan cache, which cached the execution
|
|
|
|
-- plan for a given graphql query (sans JSON variable values). After the PDV
|
|
|
|
-- refactor (see
|
|
|
|
-- [hasura/graphql-engine#4111](https://github.com/hasura/graphql-engine/pull/4111)),
|
|
|
|
-- this query plan cache was not needed anymore. For backwards compatibility
|
|
|
|
-- reasons, we still need to parse the configuration options from the CLI, although
|
|
|
|
-- the CLI option gets ignored.
|
|
|
|
--
|
|
|
|
-- Eventually, we can decide to stop parsing the CLI option
|
|
|
|
-- --query-plan-cache-size, at which point this module can be removed.
|
2019-11-25 20:12:23 +03:00
|
|
|
module Hasura.Cache.Bounded
|
2021-09-24 01:56:37 +03:00
|
|
|
( CacheSize (..),
|
|
|
|
parseCacheSize,
|
|
|
|
)
|
|
|
|
where
|
2019-11-25 20:12:23 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
import Data.Aeson qualified as J
|
|
|
|
import Data.Word (Word16)
|
|
|
|
import GHC.Natural (Natural)
|
|
|
|
import Hasura.Prelude hiding (lookup)
|
2020-07-28 01:21:24 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
newtype CacheSize = CacheSize {unCacheSize :: Word16}
|
2020-07-28 01:21:24 +03:00
|
|
|
deriving (Show, Read, Eq, Ord, Bounded, Num, Real, Integral, Enum, J.ToJSON, J.FromJSON)
|
2019-11-25 20:12:23 +03:00
|
|
|
|
2020-05-13 12:17:32 +03:00
|
|
|
parseCacheSize :: String -> Either String CacheSize
|
|
|
|
parseCacheSize v =
|
2019-12-13 22:50:45 +03:00
|
|
|
-- NOTE: naively using readMaybe Word16 will silently wrap
|
|
|
|
case readMaybe v :: Maybe Natural of
|
2020-07-28 01:21:24 +03:00
|
|
|
Just n | n <= max16 && n >= 0 -> return (CacheSize $ fromIntegral n)
|
|
|
|
_ -> throwError "cache size must be given as a number between 0 and 65535"
|
2019-12-13 22:50:45 +03:00
|
|
|
where
|
|
|
|
max16 = fromIntegral (maxBound :: Word16) :: Natural
|