Refactor snapshot diffs
- do not leak the HashMap out - use existing types (Version, PackageName)
This commit is contained in:
parent
49828b012f
commit
1e1e875bd0
4 changed files with 26 additions and 22 deletions
|
@ -5,9 +5,8 @@ module Handler.Feed
|
|||
|
||||
import Import
|
||||
import Stackage.Database
|
||||
import Data.These
|
||||
import Data.These
|
||||
import Stackage.Snapshot.Diff
|
||||
import qualified Data.HashMap.Strict as HashMap
|
||||
import Text.Blaze (text)
|
||||
|
||||
getFeedR :: Handler TypedContent
|
||||
|
@ -67,17 +66,17 @@ getContent sid2 snap = do
|
|||
<th align=right>Old
|
||||
<th align=left>New
|
||||
<tbody>
|
||||
$forall (name, VersionChange verChange) <- sortOn (toCaseFold . fst) $ HashMap.toList snapDiff
|
||||
$forall (PackageName name, VersionChange change) <- toDiffList snapDiff
|
||||
<tr>
|
||||
<th align=right>#{name}
|
||||
$case verChange
|
||||
$of This oldVersion
|
||||
<td align=right>#{oldVersion}
|
||||
$case change
|
||||
$of This (Version old)
|
||||
<td align=right>#{old}
|
||||
<td>
|
||||
$of That newVersion
|
||||
$of That (Version new)
|
||||
<td align=right>
|
||||
<td>#{newVersion}
|
||||
$of These oldVersion newVersion
|
||||
<td align=right>#{oldVersion}
|
||||
<td>#{newVersion}
|
||||
<td>#{new}
|
||||
$of These (Version old) (Version new)
|
||||
<td align=right>#{old}
|
||||
<td>#{new}
|
||||
|]
|
||||
|
|
|
@ -7,7 +7,6 @@ module Handler.StackageHome
|
|||
) where
|
||||
|
||||
import Import
|
||||
import qualified Data.HashMap.Strict as HashMap
|
||||
import Data.These
|
||||
import Data.Time (FormatTime)
|
||||
import Stackage.Database
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
module Stackage.Snapshot.Diff
|
||||
( getSnapshotDiff
|
||||
, snapshotDiff
|
||||
, SnapshotDiff
|
||||
, SnapshotDiff()
|
||||
, toDiffList
|
||||
, VersionChange(..)
|
||||
) where
|
||||
|
||||
|
@ -13,10 +14,13 @@ import ClassyPrelude
|
|||
import Data.These
|
||||
import Stackage.Database (SnapshotId, PackageListingInfo(..),
|
||||
GetStackageDatabase, getPackages)
|
||||
type PackageName = Text
|
||||
type Version = Text
|
||||
import Types
|
||||
|
||||
type SnapshotDiff = HashMap PackageName VersionChange
|
||||
newtype SnapshotDiff
|
||||
= SnapshotDiff { unSnapshotDiff :: HashMap PackageName VersionChange }
|
||||
|
||||
toDiffList :: SnapshotDiff -> [(PackageName, VersionChange)]
|
||||
toDiffList = sortOn (toCaseFold . unPackageName . fst) . HashMap.toList . unSnapshotDiff
|
||||
|
||||
-- | Versions of a package as it occurs in the listings provided to `snapshotDiff`.
|
||||
--
|
||||
|
@ -32,6 +36,8 @@ getSnapshotDiff :: GetStackageDatabase m => SnapshotId -> SnapshotId -> m Snapsh
|
|||
getSnapshotDiff a b = snapshotDiff <$> getPackages a <*> getPackages b
|
||||
|
||||
snapshotDiff :: [PackageListingInfo] -> [PackageListingInfo] -> SnapshotDiff
|
||||
snapshotDiff as bs = HashMap.filter changed $ alignWith VersionChange (toMap as) (toMap bs)
|
||||
snapshotDiff as bs =
|
||||
SnapshotDiff $ HashMap.filter changed
|
||||
$ alignWith VersionChange (toMap as) (toMap bs)
|
||||
where
|
||||
toMap = HashMap.fromList . map (pliName &&& pliVersion)
|
||||
toMap = HashMap.fromList . map (PackageName . pliName &&& Version . pliVersion)
|
||||
|
|
|
@ -33,15 +33,15 @@
|
|||
$else
|
||||
<option value=@{StackageDiffR name1 name2'}>#{toPathPiece name2'}
|
||||
<tbody>
|
||||
$forall (name, VersionChange verChange) <- sortOn (toCaseFold . fst) $ HashMap.toList snapDiff
|
||||
$forall (PackageName name, VersionChange verChange) <- toDiffList snapDiff
|
||||
<tr>
|
||||
$case verChange
|
||||
$of This oldVersion
|
||||
$of This (Version oldVersion)
|
||||
<td>#{name}-#{oldVersion}
|
||||
<td>
|
||||
$of That newVersion
|
||||
$of That (Version newVersion)
|
||||
<td>
|
||||
<td>#{name}-#{newVersion}
|
||||
$of These oldVersion newVersion
|
||||
$of These (Version oldVersion) (Version newVersion)
|
||||
<td>#{name}-#{oldVersion}
|
||||
<td>#{name}-#{newVersion}
|
||||
|
|
Loading…
Reference in a new issue