我正在尝试一种解决方案来解决部署到 Heroku 的 Ruby on Rails 6 项目中发生的重复请求。
这似乎是在使用带有超链接的锚点时发生的,因此它加载了 2 倍。
因此,它最终会生成重复的日志,因为它还调用控制器(GET -> Controller -> Model -> View)。
以下是一些证明重复请求的日志:
caio-agiani in ~ via ⬢ v14.21.3 took 10m 37s ❯ heroku logs -a levante-web -t | grep 2804:7f0:b8c2:13f:8755:4a1e:74b8:x735,172.71.10.17
2024-03-31T02:32:36.318790+00:00 heroku[router]: at=info method=GET path="/levante/search?query=caioagiani" host=app request_id=3e84b5d5-b478-41aa-b1e8-218838f37ca1 fwd="2804:7f0:b8c2:13f:8755:4a1e:74b8:x735,172.71.10.17" dyno=web.1 connect=0ms service=426ms status=200 bytes=12075 protocol=https
2024-03-31T02:32:57.648033+00:00 heroku[router]: at=info method=GET path="/levante/search?query=caioagiani" host=app request_id=f17c6635-3541-4153-8283-3811659ff00a fwd="2804:7f0:b8c2:13f:8755:4a1e:74b8:x735,172.71.10.17" dyno=web.1 connect=0ms service=330ms status=200 bytes=12077 protocol=https
2024-03-31T02:33:01.813927+00:00 heroku[router]: at=info method=GET path="/levante/shop/index" host=app request_id=cc5dd643-41c3-45e9-bffa-a73ed617d0b0 fwd="2804:7f0:b8c2:13f:8755:4a1e:74b8:x735,172.71.10.17" dyno=web.1 connect=0ms service=42ms status=200 bytes=25575 protocol=https
2024-03-31T02:33:02.145246+00:00 heroku[router]: at=info method=GET path="/levante/shop/index" host=app request_id=7bdfadad-273e-4b8a-ab88-4f0422ececaf fwd="2804:7f0:b8c2:13f:8755:4a1e:74b8:x735,172.71.10.17" dyno=web.1 connect=0ms service=39ms status=200 bytes=25564 protocol=https
PS:这可以链接到 Turbolink/Load 或一些内部 Rails 脚本(如 ujs)吗?我有证据表明是的,因为我在生产中有另一个应用程序使用完全相同的设置,但是,1 使用传统的 Rails 本机导入脚本和 css 模板(javascript_include_tag、javascript_pack_tag、stylesheet_pack_tag),另一个使用简单的 HTML 元标记
嗯,这实际上是由于涡轮链接,基本上有注入
data-turbolinks-track
,reload
[schreenshot]的部分。
这个问题也没有出现在本地,因为这个像素脚本的片段检查了
production
环境。