Improve AvatarR performance by only fetching the avatar from the DB, not the whole User
This commit is contained in:
parent
1e7482b30f
commit
660b17f279
1 changed files with 9 additions and 4 deletions
|
@ -1,12 +1,17 @@
|
|||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE NoImplicitPrelude #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Handler.Avatars where
|
||||
|
||||
import Import
|
||||
import Import hiding ( (==.) )
|
||||
|
||||
import Model.Cache ( getCached )
|
||||
import Database.Esqueleto
|
||||
import Settings.StaticR ( staticR )
|
||||
|
||||
getAvatarR :: UserId -> Handler ()
|
||||
getAvatarR = redirect <=< fmap (avatarR . entityVal) . getCached
|
||||
where avatarR user = staticR ["img", userAvatar user]
|
||||
getAvatarR = responseFrom <=< runDB . select . from . queryAvatar
|
||||
where responseFrom (a:_) = redirect $ staticR ["img", unValue a]
|
||||
responseFrom [] = notFound
|
||||
queryAvatar userId user = do
|
||||
where_ $ user ^. UserId ==. val userId
|
||||
return $ user ^. UserAvatar
|
||||
|
|
Loading…
Reference in a new issue