Skip to content

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

Merged
thecristen merged 2 commits into
mainfrom
cbj/cms-repo-caching-fix
Jul 14, 2026
Merged

fix(CMS.Repo): avoid caching errors as []#3327
thecristen merged 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

@jlucytan jlucytan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! just had a curiosity question if you happen to know the answer

Comment thread priv/gettext/en/LC_MESSAGES/dotcom.po
@thecristen thecristen removed the Not Ready for Translation Remove this when the PR is approved to trigger a Smartling translation job label Jul 14, 2026
@thecristen
thecristen enabled auto-merge (squash) July 14, 2026 14:48
@thecristen
thecristen merged commit e5499ce into main Jul 14, 2026
20 of 21 checks passed
@thecristen
thecristen deleted the cbj/cms-repo-caching-fix branch July 14, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants