@@ -23,32 +23,34 @@ defmodule CodeCorps.GitHub.API.Repository do
2323 end
2424
2525 defp fetch_issues ( % GithubRepo { github_account_login: owner , name: repo } , access_token ) do
26- # stream/lazy
26+ path = "repos/#{ owner } /#{ repo } /issues"
27+ opts = [ access_token: access_token ]
2728
29+ # stream/lazy
2830 before_operation = Timex . now
29-
30- results =
31- "repos/#{ owner } /#{ repo } /issues?per_page=8"
32- |> GitHub . lazy_get_all ( % { } , [ access_token: access_token ] )
33- |> Enum . to_list
34- |> List . flatten
35-
31+ results = path |> fetch_lazy ( opts )
3632 after_operation = Timex . now
37-
3833 IO . puts ( "Retrieving #{ results |> Enum . count } took #{ Timex . diff ( after_operation , before_operation ) } microseconds" )
3934
4035 # eager
41-
4236 before_operation = Timex . now
37+ results = path |> fetch_eager ( opts )
38+ after_operation = Timex . now
39+ IO . puts ( "Retrieving #{ results |> Enum . count } took #{ Timex . diff ( after_operation , before_operation ) } microseconds" )
4340
44- results =
45- "repos/#{ owner } /#{ repo } /issues?per_page=8"
46- |> GitHub . eager_get_all ( % { } , [ access_token: access_token ] )
47- |> Enum . to_list
48- |> List . flatten
41+ results
42+ end
4943
50- after_operation = Timex . now
44+ defp fetch_lazy ( path , opts ) do
45+ path
46+ |> GitHub . lazy_get_all ( % { } , opts )
47+ |> Enum . to_list
48+ |> List . flatten
49+ end
5150
52- IO . puts ( "Retrieving #{ results |> Enum . count } took #{ Timex . diff ( after_operation , before_operation ) } microseconds" )
51+ defp fetch_eager ( path , opts ) do
52+ path
53+ |> GitHub . eager_get_all ( % { } , opts )
54+ |> List . flatten
5355 end
5456end
0 commit comments