Skip to content

Commit

Permalink
Handler.MapFeed: switch parsing from bytestrings to text
Browse files Browse the repository at this point in the history
  • Loading branch information
astro committed May 11, 2017
1 parent 2974f33 commit 109377d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
9 changes: 2 additions & 7 deletions Handler/MapFeed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ type Attrs = [(Name, [Content])]

mapFeed :: FeedXml -> (Text -> Maybe Text) -> Source (ResourceT IO) (Flush Builder)
mapFeed (FeedXml xml) getEnclosureLink =
parseLBS def (LB.concat $ chunkify 64 xml) $=
yield xml $=
parseText' def =$=
mapEnclosures =$=
renderBuilder def =$=
CL.sequence (CL.take 2048) =$=
Expand Down Expand Up @@ -105,12 +106,6 @@ mapFeed (FeedXml xml) getEnclosureLink =
in case m_val of
Just val -> (name, [ContentText val]) : attrs'
Nothing -> attrs'
chunkify chunkSize s
| LB.null s = []
| otherwise =
let s' = LB.take chunkSize s
s'' = LB.drop chunkSize s
in s' : chunkify chunkSize s''

typeTorrent :: Text
typeTorrent = "application/x-bittorrent"
Expand Down
3 changes: 1 addition & 2 deletions Model/Feed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module Model.Feed where
import Prelude
import Data.Convertible
import Data.Text (Text)
import qualified Data.ByteString.Lazy.Char8 as LBC
import Data.Data (Typeable)
import Database.PostgreSQL.LibPQ (Connection)

Expand All @@ -19,7 +18,7 @@ userFeed user slug =
query1 "SELECT \"feed\" FROM user_feeds WHERE \"user\"=? AND \"slug\"=?"
[convert user, convert slug]

newtype FeedXml = FeedXml LBC.ByteString
newtype FeedXml = FeedXml Text
deriving (Typeable)

instance Convertible [SqlValue] FeedXml where
Expand Down

0 comments on commit 109377d

Please sign in to comment.