perf(auth): offload work creating list of correctors to db
This commit is contained in:
parent
f5af0ce500
commit
871595e068
@ -570,8 +570,8 @@ tagAccessPredicate AuthStudent = cacheAPSystemFunction SystemStudent (Just $ Rig
|
|||||||
| otherwise -> unauthorizedI MsgUnauthorizedStudent
|
| otherwise -> unauthorizedI MsgUnauthorizedStudent
|
||||||
| otherwise -> Left $ APDB $ \_ _ mAuthId _ _ -> $cachedHereBinary mAuthId . exceptT return return $ do
|
| otherwise -> Left $ APDB $ \_ _ mAuthId _ _ -> $cachedHereBinary mAuthId . exceptT return return $ do
|
||||||
authId <- maybeExceptT AuthenticationRequired $ return mAuthId
|
authId <- maybeExceptT AuthenticationRequired $ return mAuthId
|
||||||
isExamOffice <- lift $ exists [UserSystemFunctionUser ==. authId, UserSystemFunctionFunction ==. SystemStudent, UserSystemFunctionIsOptOut ==. False]
|
isStudent <- lift $ exists [UserSystemFunctionUser ==. authId, UserSystemFunctionFunction ==. SystemStudent, UserSystemFunctionIsOptOut ==. False]
|
||||||
guardMExceptT isExamOffice $ unauthorizedI MsgUnauthorizedStudent
|
guardMExceptT isStudent $ unauthorizedI MsgUnauthorizedStudent
|
||||||
return Authorized
|
return Authorized
|
||||||
tagAccessPredicate AuthExamOffice = cacheAPSchoolFunction SchoolExamOffice (Just $ Right diffHour) $ \mAuthId' route' _ examOfficeList -> if
|
tagAccessPredicate AuthExamOffice = cacheAPSchoolFunction SchoolExamOffice (Just $ Right diffHour) $ \mAuthId' route' _ examOfficeList -> if
|
||||||
| maybe True (`Set.notMember` examOfficeList) mAuthId' -> Right $ case route' of
|
| maybe True (`Set.notMember` examOfficeList) mAuthId' -> Right $ case route' of
|
||||||
@ -794,11 +794,17 @@ tagAccessPredicate AuthCorrector = cacheAPDB (Just $ Right diffMinute) AuthCache
|
|||||||
E.where_ $ sheetCorrector E.^. SheetCorrectorUser E.==. E.val authId
|
E.where_ $ sheetCorrector E.^. SheetCorrectorUser E.==. E.val authId
|
||||||
return Authorized
|
return Authorized
|
||||||
where
|
where
|
||||||
mkCorrectorList = execWriterT $ do
|
mkCorrectorList = do
|
||||||
tellM . fmap (setOf $ folded . _Value . _Just) . E.select . E.from $ \submission -> do
|
submissionCorrectors <- E.select . E.from $ \submission -> E.distinctOnOrderBy [E.asc $ submission E.^. SubmissionRatingBy] $ do
|
||||||
E.where_ . E.isJust $ submission E.^. SubmissionRatingBy
|
E.where_ . E.isJust $ submission E.^. SubmissionRatingBy
|
||||||
return $ submission E.^. SubmissionRatingBy
|
return $ submission E.^. SubmissionRatingBy
|
||||||
tellM . fmap (setOf $ folded . _Value) . E.select . E.from $ return . (E.^. SheetCorrectorUser)
|
let submissionCorrectors' = Set.fromDistinctAscList $ mapMaybe (preview $ _Value . _Just) submissionCorrectors
|
||||||
|
|
||||||
|
sheetCorrectors <- E.select . E.from $ \sheetCorrector -> E.distinctOnOrderBy [E.asc $ sheetCorrector E.^. SheetCorrectorUser] $
|
||||||
|
return $ sheetCorrector E.^. SheetCorrectorUser
|
||||||
|
let sheetCorrectors' = Set.fromDistinctAscList $ map (^. _Value) sheetCorrectors
|
||||||
|
|
||||||
|
return $ submissionCorrectors' `Set.union` sheetCorrectors'
|
||||||
tagAccessPredicate AuthExamCorrector = cacheAPDB (Just $ Right diffMinute) AuthCacheExamCorrectorList mkExamCorrectorList $ \mAuthId' route' _ examCorrectorList -> if
|
tagAccessPredicate AuthExamCorrector = cacheAPDB (Just $ Right diffMinute) AuthCacheExamCorrectorList mkExamCorrectorList $ \mAuthId' route' _ examCorrectorList -> if
|
||||||
| maybe True (`Set.notMember` examCorrectorList) mAuthId' -> Right $ case route' of
|
| maybe True (`Set.notMember` examCorrectorList) mAuthId' -> Right $ case route' of
|
||||||
_ | is _Nothing mAuthId' -> return AuthenticationRequired
|
_ | is _Nothing mAuthId' -> return AuthenticationRequired
|
||||||
|
|||||||
Reference in New Issue
Block a user