Skip to content

Commit

Permalink
Remove the MBTA Api cache because we cache that data in the relevant …
Browse files Browse the repository at this point in the history
…repo module (#1969)

* try simply removing the cache

* tests

* remove file

* remove headers we dont need

* remove references to wiremock
  • Loading branch information
anthonyshull authored Apr 17, 2024
1 parent 4a698e8 commit c282d86
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 321 deletions.
2 changes: 1 addition & 1 deletion deploy/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ services:
test: curl --fail http://localhost:4002/_health || exit 1
interval: 10s
retries: 5
start_period: 60s
start_period: 180s
timeout: 10s
volumes:
- ../:/app
Expand Down
3 changes: 1 addition & 2 deletions lib/dotcom/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ defmodule Dotcom.Application do

children =
[
{Application.get_env(:dotcom, :cache, Dotcom.Cache.Multilevel), []},
MBTA.Cache
{Application.get_env(:dotcom, :cache, Dotcom.Cache.Multilevel), []}
] ++
if Application.get_env(:dotcom, :env) != :test do
[
Expand Down
11 changes: 2 additions & 9 deletions lib/mbta/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule MBTA.Api do

use HTTPoison.Base

alias MBTA.{Cache, SentryExtra}
alias MBTA.SentryExtra
alias Util

@behaviour MBTA.Api.Behaviour
Expand All @@ -29,7 +29,6 @@ defmodule MBTA.Api do
with {time, response} <- timed_get(url, params, opts),
:ok <- log_response(url, params, time, response),
{:ok, http_response} <- response,
{:ok, http_response} <- Cache.cache_response(url, params, http_response),
{:ok, body} <- body(http_response) do
body
|> JsonApi.parse()
Expand All @@ -49,13 +48,7 @@ defmodule MBTA.Api do
api_key = Keyword.fetch!(opts, :api_key)
base_url = Keyword.fetch!(opts, :base_url)

headers =
MBTA.Headers.build(
api_key,
params: params,
url: url,
use_cache?: true
)
headers = MBTA.Headers.build(api_key)

url = base_url <> URI.encode(url)
timeout = Keyword.fetch!(opts, :timeout)
Expand Down
2 changes: 1 addition & 1 deletion lib/mbta/api/stream.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ defmodule MBTA.Api.Stream do
headers =
opts
|> Keyword.fetch!(:api_key)
|> Headers.build(use_cache?: false)
|> Headers.build()

Keyword.put(opts, :headers, headers)
end
Expand Down
147 changes: 0 additions & 147 deletions lib/mbta/cache.ex

This file was deleted.

30 changes: 2 additions & 28 deletions lib/mbta/headers.ex
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
defmodule MBTA.Headers do
@moduledoc """
Builds headers for calling the MBTA.Api.
Setting `:use_cache?` to `true` will include headers set by MBTA.Cache.cache_headers.
If `:use_cache?` is set to `true`, you must also include a `:url` and a `:params` option.
"""

alias MBTA.Cache

@type header_list :: [{String.t(), String.t()}]

@spec build(String.t() | nil, Keyword.t()) :: header_list
def build(api_key, opts) do
@spec build(String.t()) :: header_list
def build(api_key) do
[]
|> api_key_header(api_key)
|> cache_headers(opts)
|> extra_headers()
end

Expand All @@ -26,26 +20,6 @@ defmodule MBTA.Headers do
[{"x-api-key", key}, {"MBTA-Version", api_version} | headers]
end

@spec cache_headers(header_list, Keyword.t()) :: header_list
defp cache_headers(headers, opts) do
if Keyword.get(opts, :use_cache?, true) do
do_cache_headers(headers, opts)
else
headers
end
end

@spec do_cache_headers(header_list, Keyword.t()) :: header_list
defp do_cache_headers(headers, opts) do
params = Keyword.fetch!(opts, :params)
cache_headers_fn = Keyword.get(opts, :cache_headers_fn, &Cache.cache_headers/2)

opts
|> Keyword.fetch!(:url)
|> cache_headers_fn.(params)
|> Enum.reduce(headers, &[&1 | &2])
end

@spec extra_headers(header_list) :: header_list
defp extra_headers(headers) do
Util.config(:dotcom, :enable_experimental_features)
Expand Down
4 changes: 2 additions & 2 deletions playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ module.exports = defineConfig({
trace: 'on-first-retry',
userAgent: 'Playwright',
},
/* set the expect timeout to 10s */
expect: { timeout: 10000 },
/* set the expect timeout to 30s */
expect: { timeout: 30000 },
/* Configure projects for major browsers */
projects: [
{
Expand Down
101 changes: 0 additions & 101 deletions test/mbta/cache_test.exs

This file was deleted.

Loading

0 comments on commit c282d86

Please sign in to comment.