add analytics-powered 404 monitoring with FTS5 auto-resolve
All checks were successful
deploy / deploy (push) Successful in 9m48s

BrokenUrlTracker now queries real analytics pageview counts instead of
hardcoding 0, so broken URLs with prior traffic are distinguished from
bot noise. For /products/ 404s with a single FTS5 search match, auto-
creates a redirect and marks the broken URL resolved. 1232 tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-02-26 16:08:25 +00:00
parent 6e57af82fc
commit 0c54861eb6
6 changed files with 120 additions and 4 deletions

View File

@@ -20,7 +20,12 @@ defmodule BerrypodWeb.Plugs.BrokenUrlTracker do
rescue
e in Phoenix.Router.NoRouteError ->
unless static_path?(conn.request_path) do
Berrypod.Redirects.record_broken_url(conn.request_path, 0)
prior_hits = Berrypod.Analytics.count_pageviews_for_path(conn.request_path)
Berrypod.Redirects.record_broken_url(conn.request_path, prior_hits)
if prior_hits > 0 do
Berrypod.Redirects.attempt_auto_resolve(conn.request_path)
end
end
reraise e, __STACKTRACE__