transactional refactoring

This commit is contained in:
Keagan McClelland
2021-12-30 09:36:10 -07:00
parent 51851ef66c
commit 0d24ad87ff

View File

@@ -86,12 +86,7 @@ getAppsManifestR = do
let pruned = case osVersion of let pruned = case osVersion of
Nothing -> manifest Nothing -> manifest
Just av -> AppManifest . HM.mapMaybe (filterOsRecommended av) . unAppManifest $ manifest Just av -> AppManifest . HM.mapMaybe (filterOsRecommended av) . unAppManifest $ manifest
withServiceTimestamps <- withServiceTimestamps <- fmap AppManifest . HM.traverseWithKey (addFileTimestamp' appsDir) . unAppManifest $ pruned
fmap AppManifest
. HM.traverseWithKey (const pure {-addFileTimestamp' appsDir-}
)
. unAppManifest
$ pruned
pure . TypedContent "application/x-yaml" . toContent . Yaml.encode $! withServiceTimestamps pure . TypedContent "application/x-yaml" . toContent . Yaml.encode $! withServiceTimestamps
where where
addFileTimestamp' :: (MonadHandler m, MonadIO m) => FilePath -> AppIdentifier -> StoreApp -> m StoreApp addFileTimestamp' :: (MonadHandler m, MonadIO m) => FilePath -> AppIdentifier -> StoreApp -> m StoreApp
@@ -185,22 +180,21 @@ recordMetrics appId rootDir appVersion = do
Just x -> pure x Just x -> pure x
pure (sa, vi) pure (sa, vi)
-- lazy load app at requested version if it does not yet exist to automatically transfer from using apps.yaml -- lazy load app at requested version if it does not yet exist to automatically transfer from using apps.yaml
sa <- runDB $ fetchApp appId' runDB $ do
(appKey, versionKey) <- case sa of sa <- fetchApp appId'
Nothing -> do (appKey, versionKey) <- case sa of
appKey' <- runDB $ createApp appId' storeApp >>= errOnNothing status500 "duplicate app created" Nothing -> do
versionKey' <- runDB $ createAppVersion appKey' versionInfo >>= errOnNothing appKey' <- createApp appId' storeApp >>= errOnNothing status500 "duplicate app created"
status500 versionKey' <- createAppVersion appKey' versionInfo
"duplicate app version created" >>= errOnNothing status500 "duplicate app version created"
pure (appKey', versionKey') pure (appKey', versionKey')
Just a -> do Just a -> do
let appKey' = entityKey a let appKey' = entityKey a
existingVersion <- runDB $ fetchAppVersion appVersion appKey' existingVersion <- fetchAppVersion appVersion appKey'
case existingVersion of case existingVersion of
Nothing -> do Nothing -> do
appVersion' <- runDB $ createAppVersion appKey' versionInfo >>= errOnNothing appVersion' <- createAppVersion appKey' versionInfo
status500 >>= errOnNothing status500 "duplicate app version created"
"duplicate app version created" pure (appKey', appVersion')
pure (appKey', appVersion') Just v -> pure (appKey', entityKey v)
Just v -> pure (appKey', entityKey v) createMetric appKey versionKey
runDB $ createMetric appKey versionKey