@@ -23,32 +23,35 @@ defmodule CodeCorps.GitHub.API.Repository do
2323 end
2424
2525 defp fetch_issues ( % GithubRepo { github_account_login: owner , name: repo } , access_token ) do
26+ path = "repos/#{ owner } /#{ repo } /issues"
27+ opts = [ access_token: access_token ]
2628 # stream/lazy
2729
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
4136
4237 before_operation = Timex . now
38+ results = path |> fetch_eager ( opts )
39+ after_operation = Timex . now
40+ IO . puts ( "Retrieving #{ results |> Enum . count } took #{ Timex . diff ( after_operation , before_operation ) } microseconds" )
4341
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
42+ results
43+ end
4944
50- after_operation = Timex . now
45+ defp fetch_lazy ( path , opts ) do
46+ path
47+ |> GitHub . lazy_get_all ( % { } , opts )
48+ |> Enum . to_list
49+ |> List . flatten
50+ end
5151
52- IO . puts ( "Retrieving #{ results |> Enum . count } took #{ Timex . diff ( after_operation , before_operation ) } microseconds" )
52+ defp fetch_eager ( path , opts ) do
53+ path
54+ |> GitHub . eager_get_all ( % { } , opts )
55+ |> List . flatten
5356 end
5457end
0 commit comments