mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-02-16 21:05:47 +01:00
No HashMaps needed
This commit is contained in:
parent
98f2fa250f
commit
b80a7f9a52
@ -39,7 +39,6 @@ dependencies:
|
|||||||
- persistent-template
|
- persistent-template
|
||||||
- resourcet
|
- resourcet
|
||||||
- rio
|
- rio
|
||||||
- semialign
|
|
||||||
- shakespeare
|
- shakespeare
|
||||||
- tar-conduit
|
- tar-conduit
|
||||||
- template-haskell
|
- template-haskell
|
||||||
|
|||||||
@ -27,6 +27,7 @@ module Stackage.Database.Query
|
|||||||
|
|
||||||
, getAllPackages
|
, getAllPackages
|
||||||
, getPackagesForSnapshot
|
, getPackagesForSnapshot
|
||||||
|
, getPackagesForSnapshotDiff
|
||||||
, getPackageVersionForSnapshot
|
, getPackageVersionForSnapshot
|
||||||
|
|
||||||
, getLatests
|
, getLatests
|
||||||
@ -375,6 +376,22 @@ getPackagesForSnapshot snapshotId =
|
|||||||
toPackageListingInfo (Value pliName, Value pliVersion, Value pliSynopsis, Value pliOrigin) =
|
toPackageListingInfo (Value pliName, Value pliVersion, Value pliSynopsis, Value pliOrigin) =
|
||||||
PackageListingInfo {pliName, pliVersion, pliSynopsis, pliOrigin}
|
PackageListingInfo {pliName, pliVersion, pliSynopsis, pliOrigin}
|
||||||
|
|
||||||
|
getPackagesForSnapshotDiff :: GetStackageDatabase env m => SnapshotId -> m [(PackageNameP, VersionP)]
|
||||||
|
getPackagesForSnapshotDiff snapshotId =
|
||||||
|
run (map toPackageListingInfo <$>
|
||||||
|
select
|
||||||
|
(from $ \(sp `InnerJoin` pn `InnerJoin` v) -> do
|
||||||
|
on (sp ^. SnapshotPackageVersion ==. v ^. VersionId)
|
||||||
|
on (sp ^. SnapshotPackagePackageName ==. pn ^. PackageNameId)
|
||||||
|
where_ (sp ^. SnapshotPackageSnapshot ==. val snapshotId)
|
||||||
|
orderBy [asc (pn ^. PackageNameName)]
|
||||||
|
pure
|
||||||
|
( pn ^. PackageNameName
|
||||||
|
, v ^. VersionVersion
|
||||||
|
)))
|
||||||
|
where
|
||||||
|
toPackageListingInfo (Value name, Value version) = (name, version)
|
||||||
|
|
||||||
|
|
||||||
getPackageVersionForSnapshot
|
getPackageVersionForSnapshot
|
||||||
:: GetStackageDatabase env m
|
:: GetStackageDatabase env m
|
||||||
|
|||||||
@ -15,14 +15,11 @@ module Stackage.Snapshot.Diff
|
|||||||
|
|
||||||
import ClassyPrelude (sortOn, toCaseFold)
|
import ClassyPrelude (sortOn, toCaseFold)
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import Data.Align
|
|
||||||
import qualified Data.HashMap.Strict as HashMap
|
|
||||||
import qualified Data.Text as T (commonPrefixes)
|
import qualified Data.Text as T (commonPrefixes)
|
||||||
import Data.These
|
import Data.These
|
||||||
import RIO
|
import RIO
|
||||||
import Stackage.Database (GetStackageDatabase, SnapshotId,
|
import Stackage.Database (GetStackageDatabase, SnapshotId,
|
||||||
getPackagesForSnapshot)
|
getPackagesForSnapshotDiff)
|
||||||
import Stackage.Database.Types (PackageListingInfo(..))
|
|
||||||
import Types
|
import Types
|
||||||
import Web.PathPieces
|
import Web.PathPieces
|
||||||
|
|
||||||
@ -30,18 +27,15 @@ data WithSnapshotNames a
|
|||||||
= WithSnapshotNames SnapName SnapName a
|
= WithSnapshotNames SnapName SnapName a
|
||||||
|
|
||||||
newtype SnapshotDiff
|
newtype SnapshotDiff
|
||||||
= SnapshotDiff { unSnapshotDiff :: HashMap PackageNameP VersionChange }
|
= SnapshotDiff { toDiffList :: [(PackageNameP, VersionChange)] }
|
||||||
deriving (Show, Eq, Generic, Typeable)
|
deriving (Show, Eq, Generic, Typeable)
|
||||||
|
|
||||||
instance ToJSON (WithSnapshotNames SnapshotDiff) where
|
instance ToJSON (WithSnapshotNames SnapshotDiff) where
|
||||||
toJSON (WithSnapshotNames nameA nameB (SnapshotDiff diff)) =
|
toJSON (WithSnapshotNames nameA nameB (SnapshotDiff diff)) =
|
||||||
object [ "comparing" .= [toPathPiece nameA, toPathPiece nameB]
|
object [ "comparing" .= [toPathPiece nameA, toPathPiece nameB]
|
||||||
, "diff" .= toJSON (WithSnapshotNames nameA nameB <$> diff)
|
, "diff" .= toJSON (map (second (WithSnapshotNames nameA nameB)) diff)
|
||||||
]
|
]
|
||||||
|
|
||||||
toDiffList :: SnapshotDiff -> [(PackageNameP, VersionChange)]
|
|
||||||
toDiffList = sortOn (toCaseFold . textDisplay . fst) . HashMap.toList . unSnapshotDiff
|
|
||||||
|
|
||||||
versionPrefix :: VersionChange -> Maybe (Text, Text, Text)
|
versionPrefix :: VersionChange -> Maybe (Text, Text, Text)
|
||||||
versionPrefix vc = case unVersionChange vc of
|
versionPrefix vc = case unVersionChange vc of
|
||||||
These va vb -> T.commonPrefixes (textDisplay va) (textDisplay vb)
|
These va vb -> T.commonPrefixes (textDisplay va) (textDisplay vb)
|
||||||
@ -73,15 +67,24 @@ instance ToJSON (WithSnapshotNames VersionChange) where
|
|||||||
VersionChange (That b) -> object [ bKey .= b ]
|
VersionChange (That b) -> object [ bKey .= b ]
|
||||||
VersionChange (These a b) -> object [ aKey .= a, bKey .= b ]
|
VersionChange (These a b) -> object [ aKey .= a, bKey .= b ]
|
||||||
|
|
||||||
changed :: VersionChange -> Bool
|
|
||||||
changed = these (const True) (const True) (/=) . unVersionChange
|
|
||||||
|
|
||||||
getSnapshotDiff :: GetStackageDatabase env m => SnapshotId -> SnapshotId -> m SnapshotDiff
|
getSnapshotDiff :: GetStackageDatabase env m => SnapshotId -> SnapshotId -> m SnapshotDiff
|
||||||
getSnapshotDiff a b = snapshotDiff <$> getPackagesForSnapshot a <*> getPackagesForSnapshot b
|
getSnapshotDiff a b = snapshotDiff <$> getPackagesForSnapshotDiff a <*> getPackagesForSnapshotDiff b
|
||||||
|
|
||||||
snapshotDiff :: [PackageListingInfo] -> [PackageListingInfo] -> SnapshotDiff
|
snapshotDiff
|
||||||
snapshotDiff as bs =
|
:: [(PackageNameP, VersionP)]
|
||||||
SnapshotDiff $ HashMap.filter changed
|
-> [(PackageNameP, VersionP)]
|
||||||
$ alignWith VersionChange (toMap as) (toMap bs)
|
-> SnapshotDiff
|
||||||
|
snapshotDiff as0 bs0 =
|
||||||
|
SnapshotDiff $ map (second VersionChange) $ go (sortEm as0) (sortEm bs0)
|
||||||
where
|
where
|
||||||
toMap = HashMap.fromList . map (pliName &&& pliVersion)
|
sortEm = sortOn (toCaseFold . textDisplay . fst)
|
||||||
|
|
||||||
|
go as [] = map (second This) as
|
||||||
|
go [] bs = map (second That) bs
|
||||||
|
go (a:as) (b:bs) =
|
||||||
|
case compare (fst a) (fst b) of
|
||||||
|
EQ
|
||||||
|
| snd a == snd b -> go as bs
|
||||||
|
| otherwise -> (fst a, These (snd a) (snd b)) : go as bs
|
||||||
|
LT -> (fst a, This $ snd a) : go as (b:bs)
|
||||||
|
GT -> (fst b, That $ snd b) : go (a:as) bs
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user