Skip to content

Commit a369701

Browse files
committed
Remove StreamAPI
1 parent 6e576a7 commit a369701

File tree

5 files changed

+10
-102
lines changed

5 files changed

+10
-102
lines changed

lib/code_corps/github/api/api.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ defmodule CodeCorps.GitHub.API do
1414
|> marshall_response()
1515
end
1616

17-
defdelegate eager_get_all(url, headers, opts), to: CodeCorps.GitHub.EagerAPI
18-
defdelegate lazy_get_all(url, headers, opts), to: CodeCorps.GitHub.StreamAPI
17+
defdelegate get_all(url, headers, opts), to: CodeCorps.GitHub.EagerAPI
1918

2019
@doc """
2120
Get access token headers for a given `CodeCorps.User` and

lib/code_corps/github/api/eager_api.ex

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
defmodule CodeCorps.GitHub.EagerAPI do
22
@moduledoc """
3-
This module attempts to implement eager loading of a resource, by trying to
4-
fetch all of its pages in parallel.
5-
6-
This should technically be faster than lazy loading. However, it fails due to
7-
timeout errors, even when loading just two pages.
8-
9-
The assumption is that hackney needs to be configured to allow multiple
10-
requests.
3+
Eager loads a resource from the GitHub API by fetching all of its pages in
4+
parallel.
115
"""
126

13-
def eager_get_all(url, headers, options) do
7+
def get_all(url, headers, options) do
148
HTTPoison.start
159
{:ok, response} = HTTPoison.get(url, headers, options)
1610

lib/code_corps/github/api/repository.ex

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ defmodule CodeCorps.GitHub.API.Repository do
1212

1313
@spec issues(GithubRepo.t) :: {:ok, list(map)} | {:error, GitHub.api_error_struct}
1414
def issues(%GithubRepo{github_app_installation: %GithubAppInstallation{} = installation} = github_repo) do
15-
with {:ok, access_token} <- installation |> API.Installation.get_access_token(),
16-
issues <- github_repo |> fetch_issues(access_token) do
15+
with {:ok, access_token} <- API.Installation.get_access_token(installation),
16+
issues <- fetch_issues(github_repo, access_token)
17+
do
1718
{:ok, issues}
1819
else
1920
{:error, error} -> {:error, error}
@@ -25,24 +26,6 @@ defmodule CodeCorps.GitHub.API.Repository do
2526
path = "repos/#{owner}/#{repo}/issues"
2627
params = [per_page: per_page, state: "all"]
2728
opts = [access_token: access_token, params: params]
28-
29-
# stream/lazy
30-
# before_operation = Timex.now
31-
# results = path |> fetch_lazy(opts)
32-
# after_operation = Timex.now
33-
# count = results |> Enum.count
34-
# pages = count / per_page |> Float.round
35-
# elapsed = Timex.diff(after_operation, before_operation)
36-
# IO.puts("Stream: #{count} records, #{per_page} records per page, #{pages} pages total, #{elapsed} microseconds")
37-
38-
# eager
39-
GitHub.eager_get_all(path, %{}, opts)
40-
end
41-
42-
defp fetch_lazy(path, opts) do
43-
path
44-
|> GitHub.lazy_get_all(%{}, opts)
45-
|> Enum.to_list
46-
|> List.flatten
29+
GitHub.get_all(path, %{}, opts)
4730
end
4831
end

lib/code_corps/github/api/stream_api.ex

Lines changed: 0 additions & 60 deletions
This file was deleted.

lib/code_corps/github/github.ex

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,8 @@ defmodule CodeCorps.GitHub do
124124
end
125125
end
126126

127-
def lazy_get_all(endpoint, headers, options) do
128-
api().lazy_get_all(
129-
api_url_for(endpoint),
130-
headers |> Headers.user_request(options),
131-
options |> add_default_options()
132-
)
133-
end
134-
135-
def eager_get_all(endpoint, headers, options) do
136-
api().eager_get_all(
127+
def get_all(endpoint, headers, options) do
128+
api().get_all(
137129
api_url_for(endpoint),
138130
headers |> Headers.user_request(options),
139131
options |> add_default_options()

0 commit comments

Comments
 (0)