Skip to content

fix(CMS.Repo): avoid caching errors as []#3327

Open
thecristen wants to merge 2 commits into
mainfrom
cbj/cms-repo-caching-fix
Open

fix(CMS.Repo): avoid caching errors as []#3327
thecristen wants to merge 2 commits into
mainfrom
cbj/cms-repo-caching-fix

Conversation

@thecristen

Copy link
Copy Markdown
Collaborator

Scope

Prompted by investigating the missing homepage content reported in this thread this morning!

Implementation

The missing content on the page is associated with calls to CMS.Repo.whats_happening(). I noticed that its current implementation would cause errors from this call to get cached as empty lists.

How?

To dissect the initial code:

@decorate cacheable(..omitted for brevity)
def whats_happening do
  case @cms_api.view("/cms/whats-happening", []) do
    {:ok, api_data} -> Enum.map(api_data, &WhatsHappeningItem.from_api/1)
    _ -> []
  end
end

This cacheable decorator function has a default value set for its :match function as described here, TLDR the following results are not cached: :error, nil, and {:error, _} tuples. Which means the above setup obscures errors from the @cms_api.view/2 call by turning them into [], which in turn will get cached.

To prevent this from happening, I adjusted this to follow a pattern we use in many places throughout Dotcom:

def function_thats_called do
  case other_function_thats_cached do
    {:ok, value} -> (whatever)
    _ -> (whatever we want to obscure the error with)
  end
end

@decorate cacheable(...etc)
def other_function_thats_cached do
  @cms_api.view(...) # something that can actually return errors!
end

I took a cursory look for similar things happening elsewhere in the homepage, and adjusted those too.

@thecristen thecristen requested review from a team and amaisano as code owners July 10, 2026 15:28
@thecristen thecristen requested a review from jlucytan July 10, 2026 15:29
@smartling-github-connector smartling-github-connector Bot added the Not Ready for Translation Remove this when the PR is approved to trigger a Smartling translation job label Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Not Ready for Translation Remove this when the PR is approved to trigger a Smartling translation job

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant