refactor: switch everything to cached relevant study features
This commit is contained in:
parent
23fdf4af6d
commit
03e9f5be56
@ -42,7 +42,7 @@ examOfficeExamResultAuth authId examResult = authByUser E.||. authByField E.||.
|
|||||||
E.on $ studyFeatures E.^. StudyFeaturesField E.==. examOfficeField E.^. ExamOfficeFieldField
|
E.on $ studyFeatures E.^. StudyFeaturesField E.==. examOfficeField E.^. ExamOfficeFieldField
|
||||||
E.where_ . E.maybe E.false id . E.subSelectMaybe . E.from $ \course -> do
|
E.where_ . E.maybe E.false id . E.subSelectMaybe . E.from $ \course -> do
|
||||||
E.where_ $ course E.^. CourseId E.==. cId
|
E.where_ $ course E.^. CourseId E.==. cId
|
||||||
return . E.just $ isCourseStudyFeatureCached course studyFeatures
|
return . E.just $ isCourseStudyFeature course studyFeatures
|
||||||
E.where_ $ studyFeatures E.^. StudyFeaturesUser E.==. examResult E.^. ExamResultUser
|
E.where_ $ studyFeatures E.^. StudyFeaturesUser E.==. examResult E.^. ExamResultUser
|
||||||
E.&&. examOfficeField E.^. ExamOfficeFieldOffice E.==. authId
|
E.&&. examOfficeField E.^. ExamOfficeFieldOffice E.==. authId
|
||||||
E.&&. examOfficeField E.^. ExamOfficeFieldField E.==. studyFeatures E.^. StudyFeaturesField
|
E.&&. examOfficeField E.^. ExamOfficeFieldField E.==. studyFeatures E.^. StudyFeaturesField
|
||||||
|
|||||||
@ -4,9 +4,9 @@ module Handler.Utils.StudyFeatures
|
|||||||
, _userTableField, _userTableDegree, _userTableSemester, _userTableFieldType
|
, _userTableField, _userTableDegree, _userTableSemester, _userTableFieldType
|
||||||
, UserTableStudyFeatures(..)
|
, UserTableStudyFeatures(..)
|
||||||
, _UserTableStudyFeatures
|
, _UserTableStudyFeatures
|
||||||
, isRelevantStudyFeature, isRelevantStudyFeatureCached, isRelevantStudyFeatureCached'
|
, isRelevantStudyFeature, isRelevantStudyFeatureCached
|
||||||
, cacheStudyFeatureRelevance
|
, cacheStudyFeatureRelevance
|
||||||
, isCourseStudyFeature, isCourseStudyFeatureCached, courseUserStudyFeatures
|
, isCourseStudyFeature, courseUserStudyFeatures
|
||||||
, isExternalExamStudyFeature, externalExamUserStudyFeatures
|
, isExternalExamStudyFeature, externalExamUserStudyFeatures
|
||||||
, isTermStudyFeature
|
, isTermStudyFeature
|
||||||
, isAllocationStudyFeature, allocationUserStudyFeatures
|
, isAllocationStudyFeature, allocationUserStudyFeatures
|
||||||
@ -114,22 +114,11 @@ isRelevantStudyFeature termField record studyFeatures
|
|||||||
E.&&. overlap studyFeatures' E.>. overlap studyFeatures
|
E.&&. overlap studyFeatures' E.>. overlap studyFeatures
|
||||||
|
|
||||||
isRelevantStudyFeatureCached :: PersistEntity record
|
isRelevantStudyFeatureCached :: PersistEntity record
|
||||||
=> EntityField record TermId
|
|
||||||
-> E.SqlExpr (Entity record)
|
|
||||||
-> E.SqlExpr (Entity StudyFeatures)
|
|
||||||
-> E.SqlExpr (E.Value Bool)
|
|
||||||
isRelevantStudyFeatureCached termField record studyFeatures
|
|
||||||
= E.bool calcNow useCache $ studyFeatures E.^. StudyFeaturesRelevanceCached
|
|
||||||
where
|
|
||||||
useCache = isRelevantStudyFeatureCached' termField record studyFeatures
|
|
||||||
calcNow = isRelevantStudyFeature termField record studyFeatures
|
|
||||||
|
|
||||||
isRelevantStudyFeatureCached' :: PersistEntity record
|
|
||||||
=> EntityField record TermId
|
=> EntityField record TermId
|
||||||
-> E.SqlExpr (Entity record)
|
-> E.SqlExpr (Entity record)
|
||||||
-> E.SqlExpr (Entity StudyFeatures)
|
-> E.SqlExpr (Entity StudyFeatures)
|
||||||
-> E.SqlExpr (E.Value Bool)
|
-> E.SqlExpr (E.Value Bool)
|
||||||
isRelevantStudyFeatureCached' termField record studyFeatures
|
isRelevantStudyFeatureCached termField record studyFeatures
|
||||||
= E.exists . E.from $ \relevantStudyFeatures ->
|
= E.exists . E.from $ \relevantStudyFeatures ->
|
||||||
E.where_ $ relevantStudyFeatures E.^. RelevantStudyFeaturesTerm E.==. record E.^. termField
|
E.where_ $ relevantStudyFeatures E.^. RelevantStudyFeaturesTerm E.==. record E.^. termField
|
||||||
E.&&. relevantStudyFeatures E.^. RelevantStudyFeaturesStudyFeatures E.==. studyFeatures E.^. StudyFeaturesId
|
E.&&. relevantStudyFeatures E.^. RelevantStudyFeaturesStudyFeatures E.==. studyFeatures E.^. StudyFeaturesId
|
||||||
@ -153,9 +142,6 @@ cacheStudyFeatureRelevance fFilter = do
|
|||||||
isCourseStudyFeature :: E.SqlExpr (Entity Course) -> E.SqlExpr (Entity StudyFeatures) -> E.SqlExpr (E.Value Bool)
|
isCourseStudyFeature :: E.SqlExpr (Entity Course) -> E.SqlExpr (Entity StudyFeatures) -> E.SqlExpr (E.Value Bool)
|
||||||
isCourseStudyFeature = isRelevantStudyFeatureCached CourseTerm
|
isCourseStudyFeature = isRelevantStudyFeatureCached CourseTerm
|
||||||
|
|
||||||
isCourseStudyFeatureCached :: E.SqlExpr (Entity Course) -> E.SqlExpr (Entity StudyFeatures) -> E.SqlExpr (E.Value Bool)
|
|
||||||
isCourseStudyFeatureCached = isRelevantStudyFeatureCached' CourseTerm
|
|
||||||
|
|
||||||
courseUserStudyFeatures :: MonadIO m => CourseId -> UserId -> SqlPersistT m UserTableStudyFeatures
|
courseUserStudyFeatures :: MonadIO m => CourseId -> UserId -> SqlPersistT m UserTableStudyFeatures
|
||||||
courseUserStudyFeatures cId uid = do
|
courseUserStudyFeatures cId uid = do
|
||||||
feats <- E.select . E.from $ \(course `E.InnerJoin` studyFeatures `E.InnerJoin` terms `E.InnerJoin` degree) -> do
|
feats <- E.select . E.from $ \(course `E.InnerJoin` studyFeatures `E.InnerJoin` terms `E.InnerJoin` degree) -> do
|
||||||
|
|||||||
@ -64,6 +64,7 @@ import Jobs.Handler.ChangeUserDisplayEmail
|
|||||||
import Jobs.Handler.Files
|
import Jobs.Handler.Files
|
||||||
import Jobs.Handler.PersonalisedSheetFiles
|
import Jobs.Handler.PersonalisedSheetFiles
|
||||||
import Jobs.Handler.PruneOldSentMails
|
import Jobs.Handler.PruneOldSentMails
|
||||||
|
import Jobs.Handler.StudyFeatures
|
||||||
|
|
||||||
import Jobs.HealthReport
|
import Jobs.HealthReport
|
||||||
|
|
||||||
|
|||||||
@ -483,3 +483,13 @@ determineCrontab = execWriterT $ do
|
|||||||
, cronRateLimit = appNotificationRateLimit
|
, cronRateLimit = appNotificationRateLimit
|
||||||
, cronNotAfter = maybe (Right CronNotScheduled) (Right . CronTimestamp . utcToLocalTimeTZ appTZ) $ nBot =<< minimumOf (folded . _entityVal . _allocationStaffAllocationTo . to NTop . filtered (> NTop (Just registerTo))) allocs
|
, cronNotAfter = maybe (Right CronNotScheduled) (Right . CronTimestamp . utcToLocalTimeTZ appTZ) $ nBot =<< minimumOf (folded . _entityVal . _allocationStaffAllocationTo . to NTop . filtered (> NTop (Just registerTo))) allocs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasRelevanceUncached <- lift $ exists [StudyFeaturesRelevanceCached !=. True]
|
||||||
|
when hasRelevanceUncached . tell $ HashMap.singleton
|
||||||
|
(JobCtlQueue JobStudyFeaturesCacheRelevance)
|
||||||
|
Cron
|
||||||
|
{ cronInitial = CronAsap
|
||||||
|
, cronRepeat = CronRepeatOnChange
|
||||||
|
, cronRateLimit = nominalDay
|
||||||
|
, cronNotAfter = Right CronNotScheduled
|
||||||
|
}
|
||||||
|
|||||||
14
src/Jobs/Handler/StudyFeatures.hs
Normal file
14
src/Jobs/Handler/StudyFeatures.hs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
module Jobs.Handler.StudyFeatures
|
||||||
|
( dispatchJobStudyFeaturesCacheRelevance
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Import
|
||||||
|
|
||||||
|
import Handler.Utils.StudyFeatures
|
||||||
|
|
||||||
|
import qualified Database.Esqueleto as E
|
||||||
|
|
||||||
|
|
||||||
|
dispatchJobStudyFeaturesCacheRelevance :: JobHandler UniWorX
|
||||||
|
dispatchJobStudyFeaturesCacheRelevance = JobHandlerAtomic $
|
||||||
|
cacheStudyFeatureRelevance $ \studyFeatures -> studyFeatures E.^. StudyFeaturesRelevanceCached E.!=. E.val True
|
||||||
@ -97,6 +97,7 @@ data Job
|
|||||||
| JobRechunkFiles
|
| JobRechunkFiles
|
||||||
| JobDetectMissingFiles
|
| JobDetectMissingFiles
|
||||||
| JobPruneOldSentMails
|
| JobPruneOldSentMails
|
||||||
|
| JobStudyFeaturesCacheRelevance
|
||||||
deriving (Eq, Ord, Show, Read, Generic, Typeable)
|
deriving (Eq, Ord, Show, Read, Generic, Typeable)
|
||||||
data Notification
|
data Notification
|
||||||
= NotificationSubmissionRated { nSubmission :: SubmissionId }
|
= NotificationSubmissionRated { nSubmission :: SubmissionId }
|
||||||
|
|||||||
@ -138,6 +138,7 @@ migrateManual = do
|
|||||||
, ("file_content_entry_chunk_hash", "CREATE INDEX file_content_entry_chunk_hash ON \"file_content_entry\" (chunk_hash)" )
|
, ("file_content_entry_chunk_hash", "CREATE INDEX file_content_entry_chunk_hash ON \"file_content_entry\" (chunk_hash)" )
|
||||||
, ("sent_mail_bounce_secret", "CREATE INDEX sent_mail_bounce_secret ON \"sent_mail\" (bounce_secret) WHERE bounce_secret IS NOT NULL")
|
, ("sent_mail_bounce_secret", "CREATE INDEX sent_mail_bounce_secret ON \"sent_mail\" (bounce_secret) WHERE bounce_secret IS NOT NULL")
|
||||||
, ("sent_mail_recipient", "CREATE INDEX sent_mail_recipient ON \"sent_mail\" (recipient) WHERE recipient IS NOT NULL")
|
, ("sent_mail_recipient", "CREATE INDEX sent_mail_recipient ON \"sent_mail\" (recipient) WHERE recipient IS NOT NULL")
|
||||||
|
, ("study_features_relevance_cached", "CREATE INDEX study_features_relevance_cached ON \"study_features\" (relevance_cached) WHERE (relevance_cached <> true)")
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
addIndex :: Text -> Sql -> Migration
|
addIndex :: Text -> Sql -> Migration
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user