在我的Rails视图中,我使用turbo_stream_from
订阅turbo流广播来显示患者列表:
<%= turbo_stream_from :all_patients %>
我希望在创建新患者时更新此列表,因此我调用:
constly_method
Turbo::StreamsChannel.broadcast_update_to(:all_patients,...)
但是,我只想在当前有任何客户机实际订阅了:all_patients
的情况下运行这段代码,因为这段代码需要占用一些计算资源。所以我想要的是
if Turbo::StreamsChannel.broadcast_subscribed?(:all_patients)
constly_method
Turbo::StreamsChannel.broadcast_update_to(:all_patients,...)
end
有什么办法可以查到吗?
2条答案
按热度按时间ivqmmu1c1#
ActionCanble数据可以通过查询访问。例如
文件:https://api.rubyonrails.org/v7.0/classes/ActionCable/RemoteConnections.html
它很好地发挥周围的查询来解决问题。(如果你能找到正确的答案。留言给我评论。我会用它来丰富我的文章)。希望这对你有帮助
iyzzxitl2#
实际连接的用户数量,我认为不重要:
https://redis.io/commands/pubsub-channels/
这一个只适用于每个服务器示例,并为您提供每个通道连接的流的数量: