Class: SolidOps::ChannelsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/solid_ops/channels_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



7
8
9
10
11
12
13
14
# File 'app/controllers/solid_ops/channels_controller.rb', line 7

def index
  @total_messages = SolidCable::Message.count
  @channels = SolidCable::Message
              .group(:channel)
              .select("channel, COUNT(*) as message_count, MAX(created_at) as last_message_at")
              .order(Arel.sql("COUNT(*) DESC"))
              .limit(100)
end

#showObject



16
17
18
19
20
21
22
# File 'app/controllers/solid_ops/channels_controller.rb', line 16

def show
  @channel = params[:id]
  @messages = SolidCable::Message
              .where(channel: @channel)
              .order(created_at: :desc)
              .limit(100)
end

#trimObject



24
25
26
27
28
# File 'app/controllers/solid_ops/channels_controller.rb', line 24

def trim
  count = SolidCable::Message.where("created_at < ?", 1.hour.ago).count
  SolidCable::Message.where("created_at < ?", 1.hour.ago).delete_all
  redirect_to channels_path, notice: "#{count} old messages trimmed."
end