1- {-# LANGUAGE TupleSections #-}
1+ {-# LANGUAGE BangPatterns #-}
22
33-- TODO change the module name probably Distribution.Server.Features.PackageList.PackageRank
44
@@ -120,7 +120,7 @@ rankIO vers recentDownloads maintainers docs env tarCache pkgs (Just pkgI) = do
120120 temp <- temporalScore pkg lastUploads versionList recentDownloads
121121 versS <- versionScore versionList vers lastUploads pkg
122122 codeS <- codeScore documentLines srcLines
123- return ( temp <> versS <> codeS <> authorScore maintainers pkg)
123+ return $ temp <> versS <> codeS <> authorScore maintainers pkg
124124
125125 where
126126 pkg = packageDescription $ pkgDesc pkgI
@@ -132,13 +132,17 @@ rankIO vers recentDownloads maintainers docs env tarCache pkgs (Just pkgI) = do
132132 versionList :: [Version ]
133133 versionList = sortBy (flip compare )
134134 $ 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
142146
143147 documentBlob :: IO (Maybe BlobStorage. BlobId )
144148 documentBlob = queryDocumentation docs pkgId
@@ -149,8 +153,6 @@ rankIO vers recentDownloads maintainers docs env tarCache pkgs (Just pkgI) = do
149153 return $ liftM2 (,) path (join $ liftM2 T. lookup index path)
150154 documentLines :: IO Float
151155 documentLines = documentationEntr >>= filterLinesTar (const True )
152- srcLines :: IO Float
153- srcLines = packageEntr >>= filterLinesTar (isExtensionOf " .hs" )
154156
155157 filterLinesTar
156158 :: (FilePath -> Bool ) -> Maybe (FilePath , T. TarIndexEntry ) -> IO Float
0 commit comments