<commit_before>module SqlProbe
  class LiveController < SqlProbe::ApplicationController
    include Tubesock::Hijack

    def index
      SqlProbe.listening = true
    end

    def feed
      hijack do |client|
        subscription = ActiveSupport::Notifications.subscribe('sql_probe.file') do |name, started, finished, unique_id, data|
          client.send_data(YAML.load_file(data[:path]).merge(path: data[:path]).to_json)
        end
        client.instance_variable_set(:@sql_probe_subscription, subscription)

        client.onopen do
          client.send_data 'Connected'
          send_recent_files(client, params[:preload].to_i) if params[:preload]
        end

        client.onclose do
          ActiveSupport::Notifications.unsubscribe(client.instance_variable_get(:@sql_probe_subscription))
        end
      end
    end

    def send_recent_files(client, max)
      recent = SqlProbe.output_files.sort_by { |f| File.mtime(f) }.reverse[0..max]
      recent.each { |f| client.send_data(YAML.load_file(f).to_json) }
    end
  end<commit_msg>Always start listening in live controller<commit_after>module SqlProbe
  class LiveController < SqlProbe::ApplicationController
    include Tubesock::Hijack

    def index
      SqlProbe.listening = true
    end

    def feed
      SqlProbe.listening = true
      hijack do |client|
        subscription = ActiveSupport::Notifications.subscribe('sql_probe.file') do |name, started, finished, unique_id, data|
          client.send_data(YAML.load_file(data[:path]).merge(path: data[:path]).to_json)
        end
        client.instance_variable_set(:@sql_probe_subscription, subscription)

        client.onopen do
          client.send_data 'Connected'
          send_recent_files(client, params[:preload].to_i) if params[:preload]
        end

        client.onclose do
          ActiveSupport::Notifications.unsubscribe(client.instance_variable_get(:@sql_probe_subscription))
        end
      end
    end

    def send_recent_files(client, max)
      recent = SqlProbe.output_files.sort_by { |f| File.mtime(f) }.reverse[0..max]
      recent.each { |f| client.send_data(YAML.load_file(f).to_json) }
    end
  end
{'fraction_non_alphanumeric': 0.09787626962142197, 'fraction_numerical': 0.0009233610341643582, 'mean_word_length': 3.1833976833976836, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2225042', 'n_tokens_mistral': 673, 'n_tokens_neox': 659, 'n_words': 122}