Class: SolidLog::UI::LogStreamChannel
- Inherits:
-
ApplicationCable::Channel
- Object
- ActionCable::Channel::Base
- ApplicationCable::Channel
- SolidLog::UI::LogStreamChannel
- Defined in:
- app/channels/solid_log/ui/log_stream_channel.rb
Constant Summary collapse
- CACHE_NAMESPACE =
"solid_log:active_filters"- CACHE_EXPIRY =
5.minutes
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.active_filter_combinations ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/channels/solid_log/ui/log_stream_channel.rb', line 45 def self.active_filter_combinations # Read all active filter combinations from cache active_keys = Rails.cache.read("#{CACHE_NAMESPACE}:keys") || [] filters_hash = {} active_keys.each do |key| cache_key = "#{CACHE_NAMESPACE}:#{key}" filters = Rails.cache.read(cache_key) filters_hash[key] = filters if filters end filters_hash end |
Instance Method Details
#refresh_subscription ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'app/channels/solid_log/ui/log_stream_channel.rb', line 35 def refresh_subscription # Called periodically by client to keep subscription active in cache # This prevents the filter from expiring while user is actively watching if @filter_key cache_key = "#{CACHE_NAMESPACE}:#{@filter_key}" Rails.cache.write(cache_key, @filters, expires_in: CACHE_EXPIRY) register_active_filter_key(@filter_key) end end |
#subscribed ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/channels/solid_log/ui/log_stream_channel.rb', line 7 def subscribed # Store the filters for this subscription @filters = params[:filters] || {} @filter_key = generate_filter_key(@filters) # Subscribe to new entries broadcast from service # Service broadcasts entry IDs, we filter and render them stream_from "solid_log_new_entries", coder: ActiveSupport::JSON do |data| handle_new_entries(data["entry_ids"]) if data["entry_ids"] end # Register this filter combination in Rails.cache # Expires after 5 minutes of inactivity (refreshed on heartbeat) cache_key = "#{CACHE_NAMESPACE}:#{@filter_key}" Rails.cache.write(cache_key, @filters, expires_in: CACHE_EXPIRY) # Also add to the set of active filter keys register_active_filter_key(@filter_key) end |
#unsubscribed ⇒ Object
27 28 29 30 31 32 33 |
# File 'app/channels/solid_log/ui/log_stream_channel.rb', line 27 def unsubscribed # Cleanup when channel is unsubscribed stop_all_streams # Cache entries will expire naturally after CACHE_EXPIRY # This handles the case where multiple clients use same filters end |