From 942c8bd59d05c70c1513994b353dd42ea361b679 Mon Sep 17 00:00:00 2001 From: Wolfgang Witt Date: Tue, 6 Apr 2021 11:24:41 +0200 Subject: [PATCH] chore: only write favourites to db when userMaxFavourites>0 --- src/Foundation/Yesod/Middleware.hs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Foundation/Yesod/Middleware.hs b/src/Foundation/Yesod/Middleware.hs index 95d3629f0..683bb8ab6 100644 --- a/src/Foundation/Yesod/Middleware.hs +++ b/src/Foundation/Yesod/Middleware.hs @@ -184,11 +184,9 @@ updateFavourites cData = void . withReaderT projectBackend . runMaybeT $ do mcid <- (for cData $ \(tid, ssh, csh) -> MaybeT . getKeyBy $ TermSchoolCourseShort tid ssh csh) :: MaybeT (SqlPersistT m) (Maybe CourseId) User{userMaxFavourites} <- MaybeT $ get uid - -- TODO optimize for `userMaxFavourites == 0` - -- no need to store (upsert?) them, since they will be removed in the pruning step anyway! - -- update Favourites - for_ mcid $ \cid -> + -- no need to store them with userMaxFavourites==0, since they will be removed in the pruning step anyway! + when (userMaxFavourites > 0) $ for_ mcid $ \cid -> void . lift $ upsertBy (UniqueCourseFavourite uid cid) (CourseFavourite uid cid FavouriteVisited now)