Compare commits

...

6 Commits

Author SHA1 Message Date
Sarah Vaupel
9f8d26371d update flake.nix 2024-01-18 02:48:17 +01:00
Sarah Vaupel
63efd5c56e Merge branch 'master' into uni2work 2024-01-18 02:48:02 +01:00
Gregor Kleen
a59f63e033 Use displayException 2021-06-30 15:53:11 +02:00
Gregor Kleen
cb75192e0c Merge branch 'master' into uni2work 2021-06-27 13:59:35 +02:00
Gregor Kleen
85cbc00419 Improve per-request-cache performance 2021-03-25 15:33:31 +01:00
Gregor Kleen
1f122a6eac fix build on nix 2021-03-25 15:33:23 +01:00
11 changed files with 140 additions and 19 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use flake

62
flake.lock Normal file
View File

@ -0,0 +1,62 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github"
},
"original": {
"owner": "numtide",
"ref": "main",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1705540563,
"narHash": "sha256-r+FCYt03n1PjIUBMryj7whxe91K6Wss64yyg2B5VpL8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "665eccfa33f6b187ded1e3355d5a2acb4961c705",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "master",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

30
flake.nix Normal file
View File

@ -0,0 +1,30 @@
{
inputs = {
nixpkgs = {
type = "github";
owner = "NixOS";
repo = "nixpkgs";
ref = "master";
};
flake-utils = {
type = "github";
owner = "numtide";
repo = "flake-utils";
ref = "main";
};
};
outputs = { self, nixpkgs, flake-utils, ... }: flake-utils.lib.eachDefaultSystem
(system:
let pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
in {
devShell = pkgs.mkShell {
name = "uni2work-yesod";
nativeBuildInputs = with pkgs.haskellPackages; [ stack ];
};
}
);
}

8
nixpkgs.nix Normal file
View File

@ -0,0 +1,8 @@
import (
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in fetchTarball {
url = "https://api.github.com/repos/NixOS/nixpkgs/tarball/${lock.nodes.nixpkgs.locked.rev}";
sha256 = lock.nodes.nixpkgs.locked.narHash;
}
)

14
stack.nix Normal file
View File

@ -0,0 +1,14 @@
{ ghc, nixpkgs ? import ./nixpkgs.nix }:
let
# haskellPackages = import ./stackage.nix { inherit nixpkgs; };
haskellPackages = pkgs.haskellPackages;
inherit (nixpkgs {}) pkgs;
in pkgs.haskell.lib.buildStackProject {
inherit ghc;
inherit (haskellPackages) stack;
name = "stackenv";
buildInputs = with pkgs;
[ zlib
];
}

View File

@ -1,4 +1,10 @@
resolver: lts-18.3
nix:
packages: []
pure: false
shell-file: ./stack.nix
add-gc-roots: false
resolver: lts-21.25
packages:
- ./yesod-core
- ./yesod-static

View File

@ -13,7 +13,7 @@ packages:
hackage: attoparsec-aeson-2.1.0.0
snapshots:
- completed:
sha256: 694573e96dca34db5636edb1fe6c96bb233ca0f9fb96c1ead1671cdfa9bd73e9
size: 585603
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/3.yaml
original: lts-18.3
sha256: a81fb3877c4f9031e1325eb3935122e608d80715dc16b586eb11ddbff8671ecd
size: 640086
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/25.yaml
original: lts-21.25

View File

@ -1150,9 +1150,9 @@ cached action = do
eres <- Cache.cached cache action
case eres of
Right res -> return res
Left (newCache, res) -> do
Left (updateCache, res) -> do
gs <- get
let merged = newCache `HM.union` ghsCache gs
let merged = updateCache $ ghsCache gs
put $ gs { ghsCache = merged }
return res
@ -1193,9 +1193,9 @@ cachedBy k action = do
eres <- Cache.cachedBy cache k action
case eres of
Right res -> return res
Left (newCache, res) -> do
Left (updateCache, res) -> do
gs <- get
let merged = newCache `HM.union` ghsCacheBy gs
let merged = updateCache $ ghsCacheBy gs
put $ gs { ghsCacheBy = merged }
return res

View File

@ -17,7 +17,7 @@ import Yesod.Core.Content
import Yesod.Core.Types
import qualified Network.HTTP.Types as H
import qualified Data.Text as T
import Control.Exception (SomeException, handle)
import Control.Exception (SomeException, handle, displayException)
import Data.ByteString.Builder (lazyByteString, toLazyByteString)
import qualified Data.ByteString.Lazy as L
import qualified Data.Map as Map
@ -101,7 +101,7 @@ evaluateContent (ContentBuilder b mlen) = handle f $ do
len `seq` return (Right $ ContentBuilder (lazyByteString lbs) mlen')
where
f :: SomeException -> IO (Either ErrorResponse Content)
f = return . Left . InternalError . T.pack . show
f = return . Left . InternalError . T.pack . displayException
evaluateContent c = return (Right c)
getStatus :: ErrorResponse -> H.Status

View File

@ -64,11 +64,11 @@ toErrorHandler e0 = handleAny errFromShow $
Just (HCError x) -> evaluate $!! x
_ -> errFromShow e0
-- | Generate an @ErrorResponse@ based on the shown version of the exception
-- | Generate an @ErrorResponse@ based on the displayed version of the exception
errFromShow :: SomeException -> IO ErrorResponse
errFromShow x = do
text <- evaluate (T.pack $ show x) `catchAny` \_ ->
return (T.pack "Yesod.Core.Internal.Run.errFromShow: show of an exception threw an exception")
text <- evaluate (T.pack $ displayException x) `catchAny` \_ ->
return (T.pack "Yesod.Core.Internal.Run.errFromShow: display of an exception threw an exception")
return $ InternalError text
-- | Do a basic run of a handler, getting some contents and the final

View File

@ -32,12 +32,12 @@ type KeyedTypeMap = HashMap (TypeRep, ByteString) Dynamic
cached :: (Monad m, Typeable a)
=> TypeMap
-> m a -- ^ cache the result of this action
-> m (Either (TypeMap, a) a) -- ^ Left is a cache miss, Right is a hit
-> m (Either (TypeMap -> TypeMap, a) a) -- ^ Left is a cache miss, Right is a hit
cached cache action = case cacheGet cache of
Just val -> return $ Right val
Nothing -> do
val <- action
return $ Left (cacheSet val cache, val)
return $ Left (cacheSet val, val)
-- | Retrieves a value from the cache
--
@ -72,12 +72,12 @@ cachedBy :: (Monad m, Typeable a)
=> KeyedTypeMap
-> ByteString -- ^ a cache key
-> m a -- ^ cache the result of this action
-> m (Either (KeyedTypeMap, a) a) -- ^ Left is a cache miss, Right is a hit
-> m (Either (KeyedTypeMap -> KeyedTypeMap, a) a) -- ^ Left is a cache miss, Right is a hit
cachedBy cache k action = case cacheByGet k cache of
Just val -> return $ Right val
Nothing -> do
val <- action
return $ Left (cacheBySet k val cache, val)
return $ Left (cacheBySet k val, val)
-- | Retrieves a value from the keyed cache
--
@ -93,4 +93,4 @@ cacheByGet key c = res
--
-- @since 1.6.10
cacheBySet :: Typeable a => ByteString -> a -> KeyedTypeMap -> KeyedTypeMap
cacheBySet key v cache = insert (typeOf v, key) (toDyn v) cache
cacheBySet key v cache = insert (typeOf v, key) (toDyn v) cache