From 660b17f27934eff8b90a7b5be1c769ecc51ea9a5 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Fri, 13 Oct 2017 22:29:22 +1100 Subject: [PATCH] Improve AvatarR performance by only fetching the avatar from the DB, not the whole User --- src/Handler/Avatars.hs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Handler/Avatars.hs b/src/Handler/Avatars.hs index 2bc2e17..5a374c5 100644 --- a/src/Handler/Avatars.hs +++ b/src/Handler/Avatars.hs @@ -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