Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use toEncoding for toPersistValueJSON #1541

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions persistent/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
7 changes: 3 additions & 4 deletions persistent/Database/Persist/Class/PersistEntity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..))

Expand All @@ -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
Expand Down Expand Up @@ -452,7 +451,7 @@ idField = "_id"
-- toPersistValue = toPersistValueJSON
-- @
toPersistValueJSON :: ToJSON a => a -> PersistValue
toPersistValueJSON = PersistText . LT.toStrict . TB.toLazyText . encodeToTextBuilder . toJSON
toPersistValueJSON = PersistByteString . B.toStrict . encodingToLazyByteString . toEncoding
matthewbauer marked this conversation as resolved.
Show resolved Hide resolved

-- | Convenience function for getting a free 'PersistField' instance
-- from a type with JSON instances. The JSON parser used will accept JSON
Expand Down
Loading