diff --git a/persistent/ChangeLog.md b/persistent/ChangeLog.md index ceb25f41a..7e3d9902c 100644 --- a/persistent/ChangeLog.md +++ b/persistent/ChangeLog.md @@ -1,5 +1,12 @@ # Changelog for persistent +## Unreleased + +* [#1541](https://github.com/yesodweb/persistent/pull/1541) + * `toPersistValueJSON` now uses `ToJSON`’s `toEncoding` instead of + `toJSON`. This provides a performance benefit because Aeson no + longer needs to construct intermediate `Value`s. + ## 2.14.6.1 * [#1528](https://github.com/yesodweb/persistent/pull/1528) diff --git a/persistent/Database/Persist/Class/PersistEntity.hs b/persistent/Database/Persist/Class/PersistEntity.hs index 81d019339..58f47deb9 100644 --- a/persistent/Database/Persist/Class/PersistEntity.hs +++ b/persistent/Database/Persist/Class/PersistEntity.hs @@ -53,9 +53,10 @@ import Data.Aeson , (.=) ) import qualified Data.Aeson.Parser as AP -import Data.Aeson.Text (encodeToTextBuilder) +import Data.Aeson.Encoding (encodingToLazyByteString) import Data.Aeson.Types (Parser, Result(Error, Success)) import Data.Attoparsec.ByteString (parseOnly) +import qualified Data.ByteString as B import Data.Functor.Identity import Web.PathPieces (PathMultiPiece(..), PathPiece(..)) @@ -71,8 +72,6 @@ import Data.Maybe (isJust) import Data.Text (Text) import qualified Data.Text as T import qualified Data.Text.Encoding as TE -import qualified Data.Text.Lazy as LT -import qualified Data.Text.Lazy.Builder as TB import GHC.Generics import GHC.OverloadedLabels import GHC.TypeLits @@ -452,7 +451,7 @@ idField = "_id" -- toPersistValue = toPersistValueJSON -- @ toPersistValueJSON :: ToJSON a => a -> PersistValue -toPersistValueJSON = PersistText . LT.toStrict . TB.toLazyText . encodeToTextBuilder . toJSON +toPersistValueJSON = PersistText . LT.toStrict . encodeToLazyText -- | Convenience function for getting a free 'PersistField' instance -- from a type with JSON instances. The JSON parser used will accept JSON