mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-01-26 02:41:56 +01:00
Cache latest version
This commit is contained in:
parent
ebc27e0746
commit
26d4a2312e
@ -39,7 +39,7 @@ import Network.HTTP.Types (status200, status404)
|
|||||||
import Pantry (CabalFileInfo(..), DidUpdateOccur(..),
|
import Pantry (CabalFileInfo(..), DidUpdateOccur(..),
|
||||||
HpackExecutable(HpackBundled), PackageIdentifierRevision(..),
|
HpackExecutable(HpackBundled), PackageIdentifierRevision(..),
|
||||||
defaultCasaMaxPerRequest, defaultCasaRepoPrefix,
|
defaultCasaMaxPerRequest, defaultCasaRepoPrefix,
|
||||||
defaultHackageSecurityConfig)
|
defaultHackageSecurityConfig, defaultSnapshotLocation)
|
||||||
import Pantry.Internal.Stackage (HackageTarballResult(..), PantryConfig(..),
|
import Pantry.Internal.Stackage (HackageTarballResult(..), PantryConfig(..),
|
||||||
Storage(..), forceUpdateHackageIndex,
|
Storage(..), forceUpdateHackageIndex,
|
||||||
getHackageTarball, packageTreeKey)
|
getHackageTarball, packageTreeKey)
|
||||||
@ -189,6 +189,7 @@ stackageServerCron StackageCronOptions {..} = do
|
|||||||
, pcConnectionCount = connectionCount
|
, pcConnectionCount = connectionCount
|
||||||
, pcCasaRepoPrefix = defaultCasaRepoPrefix
|
, pcCasaRepoPrefix = defaultCasaRepoPrefix
|
||||||
, pcCasaMaxPerRequest = defaultCasaMaxPerRequest
|
, pcCasaMaxPerRequest = defaultCasaMaxPerRequest
|
||||||
|
, pcSnapshotLocation = defaultSnapshotLocation
|
||||||
}
|
}
|
||||||
currentHoogleVersionId <-
|
currentHoogleVersionId <-
|
||||||
runRIO logFunc $ getCurrentHoogleVersionIdWithPantryConfig pantryConfig
|
runRIO logFunc $ getCurrentHoogleVersionIdWithPantryConfig pantryConfig
|
||||||
@ -228,7 +229,7 @@ runStackageUpdate doNotUpload = do
|
|||||||
runConduit $ sourceSnapshots .| foldMC (createOrUpdateSnapshot corePackageGetters) (pure ())
|
runConduit $ sourceSnapshots .| foldMC (createOrUpdateSnapshot corePackageGetters) (pure ())
|
||||||
unless doNotUpload uploadSnapshotsJSON
|
unless doNotUpload uploadSnapshotsJSON
|
||||||
buildAndUploadHoogleDB doNotUpload
|
buildAndUploadHoogleDB doNotUpload
|
||||||
run $ mapM_ (`rawExecute` []) ["COMMIT", "VACUUM", "BEGIN"]
|
run $ mapM_ (`rawExecute` []) ["TRUNCATE TABLE latest_version", "COMMIT", "VACUUM", "BEGIN"]
|
||||||
|
|
||||||
|
|
||||||
-- | This will look at 'global-hints.yaml' and will create core package getters that are reused
|
-- | This will look at 'global-hints.yaml' and will create core package getters that are reused
|
||||||
|
|||||||
@ -89,7 +89,7 @@ import qualified Database.Persist as P
|
|||||||
import Pantry.Internal.Stackage (EntityField(..), PackageName,
|
import Pantry.Internal.Stackage (EntityField(..), PackageName,
|
||||||
Version, getBlobKey, getPackageNameById,
|
Version, getBlobKey, getPackageNameById,
|
||||||
getPackageNameId, getTreeForKey, getVersionId,
|
getPackageNameId, getTreeForKey, getVersionId,
|
||||||
loadBlobById, storeBlob, mkSafeFilePath)
|
loadBlobById, storeBlob, mkSafeFilePath, versionVersion)
|
||||||
import RIO hiding (on, (^.))
|
import RIO hiding (on, (^.))
|
||||||
import qualified RIO.Map as Map
|
import qualified RIO.Map as Map
|
||||||
import qualified RIO.Set as Set
|
import qualified RIO.Set as Set
|
||||||
@ -415,40 +415,54 @@ getPackageVersionForSnapshot snapshotId pname =
|
|||||||
|
|
||||||
getLatest ::
|
getLatest ::
|
||||||
FromPreprocess t
|
FromPreprocess t
|
||||||
=> PackageNameP
|
=> PackageNameId
|
||||||
-> (t -> SqlExpr (Value SnapshotId))
|
-> (t -> SqlExpr (Value SnapshotId))
|
||||||
-> (t -> SqlQuery ())
|
-> (t -> SqlQuery ())
|
||||||
-> ReaderT SqlBackend (RIO env) (Maybe LatestInfo)
|
-> ReaderT SqlBackend (RIO env) (Maybe SnapshotPackageId)
|
||||||
getLatest pname onWhich orderWhich =
|
getLatest pnameid onWhich orderWhich =
|
||||||
selectApplyMaybe
|
selectApplyMaybe
|
||||||
toLatestInfo
|
unValue
|
||||||
(from $ \(which `InnerJoin` snap `InnerJoin` sp `InnerJoin` pn `InnerJoin` v) -> do
|
(from $ \(which `InnerJoin` snap `InnerJoin` sp) -> do
|
||||||
on (sp ^. SnapshotPackageVersion ==. v ^. VersionId)
|
|
||||||
on (sp ^. SnapshotPackagePackageName ==. pn ^. PackageNameId)
|
|
||||||
on (sp ^. SnapshotPackageSnapshot ==. snap ^. SnapshotId)
|
on (sp ^. SnapshotPackageSnapshot ==. snap ^. SnapshotId)
|
||||||
on (snap ^. SnapshotId ==. onWhich which)
|
on (snap ^. SnapshotId ==. onWhich which)
|
||||||
where_ (pn ^. PackageNameName ==. val pname)
|
where_ (sp ^. SnapshotPackagePackageName ==. val pnameid)
|
||||||
orderWhich which
|
orderWhich which
|
||||||
limit 1
|
limit 1
|
||||||
pure (snap ^. SnapshotName, v ^. VersionVersion, sp ^. SnapshotPackageRevision))
|
pure (sp ^. SnapshotPackageId))
|
||||||
where
|
|
||||||
toLatestInfo (snapName, ver, mrev) =
|
|
||||||
LatestInfo (unValue snapName) $ toVersionMRev (unValue ver) (unValue mrev)
|
|
||||||
|
|
||||||
|
|
||||||
getLatests :: PackageNameP -> ReaderT SqlBackend (RIO env) [LatestInfo]
|
getLatests :: PackageNameP -> ReaderT SqlBackend (RIO env) [LatestInfo]
|
||||||
getLatests pname = do
|
getLatests pname = do
|
||||||
mLts <-
|
pid <- getPackageNameId $ unPackageNameP pname
|
||||||
getLatest
|
mlatest <- getBy $ UniqueLatestVersion pid
|
||||||
pname
|
(mlts, mnightly) <-
|
||||||
(^. LtsSnap)
|
case mlatest of
|
||||||
(\lts -> orderBy [desc (lts ^. LtsMajor), desc (lts ^. LtsMinor)])
|
Nothing -> do
|
||||||
mNightly <-
|
mLts <-
|
||||||
getLatest
|
getLatest
|
||||||
pname
|
pid
|
||||||
(^. NightlySnap)
|
(^. LtsSnap)
|
||||||
(\nightly -> orderBy [desc (nightly ^. NightlyDay)])
|
(\lts -> orderBy [desc (lts ^. LtsMajor), desc (lts ^. LtsMinor)])
|
||||||
pure $ catMaybes [mLts, mNightly]
|
mNightly <-
|
||||||
|
getLatest
|
||||||
|
pid
|
||||||
|
(^. NightlySnap)
|
||||||
|
(\nightly -> orderBy [desc (nightly ^. NightlyDay)])
|
||||||
|
insert_ LatestVersion
|
||||||
|
{ latestVersionPackageName = pid
|
||||||
|
, latestVersionLts = mLts
|
||||||
|
, latestVersionNightly = mNightly
|
||||||
|
}
|
||||||
|
pure (mLts, mNightly)
|
||||||
|
Just (Entity _ (LatestVersion _name mlts mnightly)) -> pure (mlts, mnightly)
|
||||||
|
for (catMaybes [mlts, mnightly]) $ \spid -> do
|
||||||
|
sp <- maybe (error "impossible") id <$> get spid
|
||||||
|
snap <- maybe (error "impossible") id <$> get (snapshotPackageSnapshot sp)
|
||||||
|
version <- maybe (error "impossible") id <$> get (snapshotPackageVersion sp)
|
||||||
|
pure LatestInfo
|
||||||
|
{ liSnapName = snapshotName snap
|
||||||
|
, liVersionRev = toVersionMRev (versionVersion version) (snapshotPackageRevision sp)
|
||||||
|
}
|
||||||
|
|
||||||
-- | Looks up in pantry the latest information about the package on Hackage.
|
-- | Looks up in pantry the latest information about the package on Hackage.
|
||||||
getHackageLatestVersion ::
|
getHackageLatestVersion ::
|
||||||
|
|||||||
@ -42,6 +42,8 @@ module Stackage.Database.Schema
|
|||||||
, DepId
|
, DepId
|
||||||
, Deprecated(..)
|
, Deprecated(..)
|
||||||
, DeprecatedId
|
, DeprecatedId
|
||||||
|
, LatestVersion(..)
|
||||||
|
, LatestVersionId
|
||||||
-- ** Pantry
|
-- ** Pantry
|
||||||
, module PS
|
, module PS
|
||||||
) where
|
) where
|
||||||
@ -119,6 +121,13 @@ Deprecated
|
|||||||
package PackageNameId
|
package PackageNameId
|
||||||
inFavourOf [PackageNameId]
|
inFavourOf [PackageNameId]
|
||||||
UniqueDeprecated package
|
UniqueDeprecated package
|
||||||
|
|
||||||
|
-- Cache table for efficiency
|
||||||
|
LatestVersion
|
||||||
|
packageName PackageNameId
|
||||||
|
lts SnapshotPackageId Maybe
|
||||||
|
nightly SnapshotPackageId Maybe
|
||||||
|
UniqueLatestVersion packageName
|
||||||
|]
|
|]
|
||||||
|
|
||||||
_hideUnusedWarnings :: (SchemaId, LtsId, NightlyId, SnapshotHoogleDbId) -> ()
|
_hideUnusedWarnings :: (SchemaId, LtsId, NightlyId, SnapshotHoogleDbId) -> ()
|
||||||
|
|||||||
@ -7,7 +7,7 @@ extra-deps:
|
|||||||
- yesod-gitrepo-0.3.0@sha256:7aad996935065726ce615c395d735cc01dcef3993b1788f670f6bfc866085e02,1191
|
- yesod-gitrepo-0.3.0@sha256:7aad996935065726ce615c395d735cc01dcef3993b1788f670f6bfc866085e02,1191
|
||||||
- lukko-0.1.1.1@sha256:5c674bdd8a06b926ba55d872abe254155ed49a58df202b4d842b643e5ed6bcc9,4289
|
- lukko-0.1.1.1@sha256:5c674bdd8a06b926ba55d872abe254155ed49a58df202b4d842b643e5ed6bcc9,4289
|
||||||
- github: commercialhaskell/pantry
|
- github: commercialhaskell/pantry
|
||||||
commit: ed48bebc30e539280ad7e13680480be2b87b97ea
|
commit: c4e7c3dff9770e7937c93edfb6564dd6a1acd55e
|
||||||
- github: fpco/casa
|
- github: fpco/casa
|
||||||
commit: fc0ed26858bfc4f2966ed2dfb2871bae9266dda6
|
commit: fc0ed26858bfc4f2966ed2dfb2871bae9266dda6
|
||||||
subdirs:
|
subdirs:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user