1
- {-# LANGUAGE TupleSections #-}
1
+ {-# LANGUAGE BangPatterns #-}
2
2
3
3
-- TODO change the module name probably Distribution.Server.Features.PackageList.PackageRank
4
4
@@ -120,7 +120,7 @@ rankIO vers recentDownloads maintainers docs env tarCache pkgs (Just pkgI) = do
120
120
temp <- temporalScore pkg lastUploads versionList recentDownloads
121
121
versS <- versionScore versionList vers lastUploads pkg
122
122
codeS <- codeScore documentLines srcLines
123
- return ( temp <> versS <> codeS <> authorScore maintainers pkg)
123
+ return $ temp <> versS <> codeS <> authorScore maintainers pkg
124
124
125
125
where
126
126
pkg = packageDescription $ pkgDesc pkgI
@@ -132,13 +132,17 @@ rankIO vers recentDownloads maintainers docs env tarCache pkgs (Just pkgI) = do
132
132
versionList :: [Version ]
133
133
versionList = sortBy (flip compare )
134
134
$ map (pkgVersion . package . packageDescription) (pkgDesc <$> pkgs)
135
- packageEntr = do
136
- tarB <- packageTarball tarCache pkgI
137
- return
138
- $ (\ (path, _, index) -> (path, ) <$> T. lookup index path)
139
- =<< rightToMaybe tarB
140
- rightToMaybe (Right a) = Just a
141
- rightToMaybe (Left _) = Nothing
135
+ srcLines = do
136
+ Right (path, _, _) <- packageTarball tarCache pkgI
137
+ filterLines (isExtensionOf " .hs" ) . Tar. read <$> BSL. readFile path
138
+
139
+ filterLines f = Tar. foldEntries (countLines f) 0 (const 0 )
140
+ countLines :: (FilePath -> Bool ) -> Tar. Entry -> Float -> Float
141
+ countLines f entry l = if not . f . Tar. entryPath $ entry then l else lns
142
+ where
143
+ ! lns = case Tar. entryContent entry of
144
+ (Tar. NormalFile str _) -> l + (int2Float . length $ BSL. split 10 str)
145
+ _ -> l
142
146
143
147
documentBlob :: IO (Maybe BlobStorage. BlobId )
144
148
documentBlob = queryDocumentation docs pkgId
@@ -149,8 +153,6 @@ rankIO vers recentDownloads maintainers docs env tarCache pkgs (Just pkgI) = do
149
153
return $ liftM2 (,) path (join $ liftM2 T. lookup index path)
150
154
documentLines :: IO Float
151
155
documentLines = documentationEntr >>= filterLinesTar (const True )
152
- srcLines :: IO Float
153
- srcLines = packageEntr >>= filterLinesTar (isExtensionOf " .hs" )
154
156
155
157
filterLinesTar
156
158
:: (FilePath -> Bool ) -> Maybe (FilePath , T. TarIndexEntry ) -> IO Float
0 commit comments