Эх сурвалжийг харах

inlining models functions

Jérôme Mahuet 9 жил өмнө
parent
commit
907350f923

+ 1 - 0
frameworks/Haskell/spock/src/Models/Fortune.hs

@@ -40,3 +40,4 @@ instance Ord Fortune where
 
 fetchFortunes :: PG.Connection -> IO [Fortune]
 fetchFortunes c = PG.query_ c "SELECT id, message FROM Fortune"
+{-# INLINE fetchFortunes #-}

+ 5 - 0
frameworks/Haskell/spock/src/Models/World.hs

@@ -39,6 +39,7 @@ fetchWorldById i c =
     listToMaybe <$> PG.query c
         "SELECT id, randomNumber FROM World WHERE id = ?"
         (PG.Only i)
+{-# INLINE fetchWorldById #-}
 
 -- | Get a random World from the database. For the tests
 -- the id must be bound between 1-10000
@@ -46,12 +47,14 @@ getRandomWorld :: PG.Connection -> IO (Maybe World)
 getRandomWorld c = do
     i <- randomRIO (1, 10000)
     fetchWorldById i c
+{-# INLINE getRandomWorld #-}
 
 -- | Get n random Worlds in a concurrent way.
 fetchRandomWorldsAsync :: Int -> PG.Connection -> IO [World]
 fetchRandomWorldsAsync n c = do
     maybes <- mapConcurrently (\_ -> getRandomWorld c) [1..n]
     return $ catMaybes maybes
+{-# INLINE fetchRandomWorldsAsync #-}
 
 -- | Update a World with a random number
 updateWorldRandom :: PG.Connection -> World -> IO World
@@ -59,8 +62,10 @@ updateWorldRandom c (World _id _) = do
     i <- randomRIO (1, 10000)
     _ <- PG.execute c "UPDATE World SET randomNumber = ? WHERE id = ?" (i, _id)
     return $ World _id i
+{-# INLINE updateWorldRandom #-}
 
 -- | Update a bunch of Worlds in a concurrent way.
 updateWorldsRandomAsync :: [World] -> PG.Connection -> IO [World]
 updateWorldsRandomAsync ws c =
     mapConcurrently (updateWorldRandom c) ws
+{-# INLINE updateWorldsRandomAsync #-}