mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-24 07:52:14 +03:00
11a454c2d6
This commit applies ormolu to the whole Haskell code base by running `make format`. For in-flight branches, simply merging changes from `main` will result in merge conflicts. To avoid this, update your branch using the following instructions. Replace `<format-commit>` by the hash of *this* commit. $ git checkout my-feature-branch $ git merge <format-commit>^ # and resolve conflicts normally $ make format $ git commit -a -m "reformat with ormolu" $ git merge -s ours post-ormolu https://github.com/hasura/graphql-engine-mono/pull/2404 GitOrigin-RevId: 75049f5c12f430c615eafb4c6b8e83e371e01c8e
33 lines
1.3 KiB
Haskell
33 lines
1.3 KiB
Haskell
-- | 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.
|
|
module Hasura.Cache.Bounded
|
|
( CacheSize (..),
|
|
parseCacheSize,
|
|
)
|
|
where
|
|
|
|
import Data.Aeson qualified as J
|
|
import Data.Word (Word16)
|
|
import GHC.Natural (Natural)
|
|
import Hasura.Prelude hiding (lookup)
|
|
|
|
newtype CacheSize = CacheSize {unCacheSize :: Word16}
|
|
deriving (Show, Read, Eq, Ord, Bounded, Num, Real, Integral, Enum, J.ToJSON, J.FromJSON)
|
|
|
|
parseCacheSize :: String -> Either String CacheSize
|
|
parseCacheSize v =
|
|
-- NOTE: naively using readMaybe Word16 will silently wrap
|
|
case readMaybe v :: Maybe Natural of
|
|
Just n | n <= max16 && n >= 0 -> return (CacheSize $ fromIntegral n)
|
|
_ -> throwError "cache size must be given as a number between 0 and 65535"
|
|
where
|
|
max16 = fromIntegral (maxBound :: Word16) :: Natural
|