refactor(corrector assignment): remove unnecessary redudant filtering
This commit is contained in:
parent
16716d50d0
commit
f6f4266067
@ -1140,22 +1140,24 @@ assignHandler tid ssh csh cid assignSids = do
|
||||
E.on $ corrector E.^. SheetCorrectorUser E.==. user E.^. UserId
|
||||
E.where_ $ corrector E.^. SheetCorrectorSheet `E.in_` E.valList sheetIds
|
||||
return (corrector, user)
|
||||
let regular_correctors = nub $ fmap (\(_,Entity uid _) -> uid) correctors
|
||||
act_correctors <- E.select . E.distinct . E.from $ \(submission `E.InnerJoin` user) -> do
|
||||
E.on $ submission E.^. SubmissionRatingBy E.==. (E.just $ user E.^. UserId)
|
||||
E.where_ $ submission E.^. SubmissionSheet `E.in_` E.valList sheetIds
|
||||
E.where_ $ user E.^. UserId `E.notIn` E.valList regular_correctors
|
||||
return (submission E.^. SubmissionSheet, user)
|
||||
|
||||
let fakeSheetCorrector :: (E.Value SheetId, Entity User) -> (Entity SheetCorrector, Entity User)
|
||||
fakeSheetCorrector (E.Value shid, usr@(Entity uid _)) = (Entity (error "Fake SheetId") (SheetCorrector uid shid mempty CorrectorExcused), usr)
|
||||
|
||||
let correctorMap :: Map UserId (User, Map SheetName SheetCorrector)
|
||||
correctorMap = (\f -> foldl f Map.empty (correctors ++ (fakeSheetCorrector <$> act_correctors)) )
|
||||
let correctorMap' :: Map UserId (User, Map SheetName SheetCorrector)
|
||||
correctorMap' = (\f -> foldl f Map.empty correctors)
|
||||
(\acc (Entity _ sheetcorr@SheetCorrector{sheetCorrectorSheet}, Entity uid user) ->
|
||||
let shn = sheetName $ sheets ! sheetCorrectorSheet
|
||||
in Map.insertWith (\(usr, ma) (_, mb) -> (usr, Map.union ma mb)) uid (user, Map.singleton shn sheetcorr) acc
|
||||
)
|
||||
-- Lecturers may correct without being enlisted SheetCorrectors, so fetch all names
|
||||
act_correctors <- E.select . E.distinct . E.from $ \(submission `E.InnerJoin` user) -> do
|
||||
E.on $ submission E.^. SubmissionRatingBy E.==. (E.just $ user E.^. UserId)
|
||||
E.where_ $ submission E.^. SubmissionSheet `E.in_` E.valList sheetIds
|
||||
return (submission E.^. SubmissionSheet, user)
|
||||
let correctorMap :: Map UserId (User, Map SheetName SheetCorrector)
|
||||
correctorMap = (\f -> foldl f correctorMap' act_correctors)
|
||||
(\acc (E.Value sheetCorrectorSheet, Entity uid user) ->
|
||||
let shn = sheetName $ sheets ! sheetCorrectorSheet
|
||||
scr = SheetCorrector uid sheetCorrectorSheet mempty CorrectorExcused
|
||||
in Map.insertWith (\new old -> old) uid (user, Map.singleton shn scr) acc -- keep already known correctors unchanged
|
||||
)
|
||||
|
||||
submissions <- E.select . E.from $ \submission -> do
|
||||
E.where_ $ submission E.^. SubmissionSheet `E.in_` E.valList sheetIds
|
||||
|
||||
Loading…
Reference in New Issue
Block a user