Skip to content

Commit 868e58d

Browse files
committed
fixed some partial functions
1 parent 8380020 commit 868e58d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/Distribution/Server/Features/PackageRank.hs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ rankIO
114114
-> [PkgInfo]
115115
-> IO Scorer
116116

117+
rankIO _ _ _ _ _ _ [] = return (Scorer (118 + 16 + 4 + 1) 0)
117118
rankIO vers recentDownloads maintainers docs env tarCache pkgs = do
118119
temp <- temporalScore pkg lastUploads versionList recentDownloads
119120
versS <- versionScore versionList vers lastUploads pkg
@@ -131,10 +132,10 @@ rankIO vers recentDownloads maintainers docs env tarCache pkgs = do
131132
versionList = sortBy (flip compare)
132133
$ map (pkgVersion . package . packageDescription) (pkgDesc <$> pkgs)
133134
packageEntr = do
134-
tarB <- packageTarball tarCache . head $ pkgs
135+
tarB <- mapM (packageTarball tarCache) (safeHead pkgs)
135136
return
136137
$ (\(path, _, index) -> (path, ) <$> T.lookup index path)
137-
=<< rightToMaybe tarB
138+
=<< (join $ rightToMaybe <$> tarB)
138139
rightToMaybe (Right a) = Just a
139140
rightToMaybe (Left _) = Nothing
140141

@@ -243,17 +244,18 @@ temporalScore p lastUploads versionList recentDownloads = do
243244
/ (if isApp then 5 else 6)
244245
)
245246
5
246-
packageFreshness = case lastUploads of
247-
[] -> return 0
248-
_ -> freshness versionList (head lastUploads) isApp
247+
packageFreshness = case safeHead lastUploads of
248+
Nothing -> return 0
249+
(Just l) -> freshness versionList l isApp
249250
freshnessScore = fracScor 10 <$> packageFreshness
250251
-- Missing dependencyFreshnessScore for reasonable effectivity needs caching
251252
tractionScore = do
252253
fresh <- packageFreshness
253254
return $ boolScor 1 (fresh * int2Float recentDownloads > 1000)
254255

255-
rankPackagePage :: PackageDescription -> Scorer
256-
rankPackagePage p = tests <> benchs <> desc <> homeP <> sourceRp <> cats
256+
rankPackagePage :: Maybe PackageDescription -> Scorer
257+
rankPackagePage Nothing = Scorer 233 0
258+
rankPackagePage (Just p) = tests <> benchs <> desc <> homeP <> sourceRp <> cats
257259
where
258260
tests = boolScor 50 (hasTests p)
259261
benchs = boolScor 10 (hasBenchmarks p)
@@ -278,4 +280,4 @@ rankPackage versions recentDownloads maintainers docs tarCache env pkgs =
278280
total
279281
. (<>) (rankPackagePage pkgD)
280282
<$> rankIO versions recentDownloads maintainers docs env tarCache pkgs
281-
where pkgD = packageDescription $ pkgDesc $ last pkgs
283+
where pkgD = packageDescription . pkgDesc <$> safeLast pkgs

0 commit comments

Comments
 (0)