Speed up getForks by using search API

This commit is contained in:
Julian Ospald 2020-02-01 16:23:02 +01:00
parent fe9578c9d6
commit cfd1fc531b
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
1 changed files with 7 additions and 2 deletions

View File

@ -60,6 +60,8 @@ import GitHub.Data.Name
import GitHub.Data.URL
import GitHub.Data.Request
import GitHub.Endpoints.Repos
import GitHub.Endpoints.Search
import GitHub.Endpoints.Users
import GitHub.Request
import HPath
import HPath.IO
@ -326,14 +328,17 @@ getForks :: (MonadIO m, MonadReader Settings m)
=> Maybe UTCTime
-> ExceptT Error m [Repo]
getForks mtime = do
repos <- githubAuth (currentUserReposR RepoPublicityAll FetchAll)
user <- githubAuth userInfoCurrentR
let userName = untagName $ userLogin user
repos <- github_
(searchReposR $ mconcat [T.pack "user:", userName, T.pack " fork:only"])
pure $ sortBy (\x y -> compare (repoUpdatedAt y) (repoUpdatedAt x)) $ filter
(\case
Repo { repoFork = Just True, repoUpdatedAt = Just t } ->
maybe True (t >=) mtime
_ -> False
)
(toList repos)
(toList $ searchResultResults repos)