Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
add status to timespent
Browse files Browse the repository at this point in the history
  • Loading branch information
wuminzhe committed Mar 15, 2024
1 parent 9301338 commit 7516e13
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions app/controllers/messages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class MessagesController < ApplicationController
before_action :set_message, only: %i[show]
before_action -> { @messages_count = Message.count }, only: %i[index show]

# GET /messages or /messages.json
def index
Expand All @@ -12,11 +11,15 @@ def index
@messages = @messages.where(from_chain_id: from_network.chain_id) if from_network.present?
@messages = @messages.where(to_chain_id: to_network.chain_id) if to_network.present?
@messages = @messages.where(status: params[:status]) if params[:status].present?
@messages_count = @messages.count

@messages = @messages.order(block_timestamp: :desc).page(params[:page]).per(25)
end

# GET /messages/1 or /messages/1.json
def show; end
def show
@messages_count = Message.count
end

def message
if params[:tx_or_hash].start_with?('0x')
Expand All @@ -43,7 +46,7 @@ def timespent

@messages = if params[:op] == 'gt'
Message.where(
'dispatch_block_timestamp IS NOT NULL AND round(extract(epoch from(dispatch_block_timestamp - block_timestamp)))::int > ?', distance
'(dispatch_block_timestamp IS NULL AND round(extract(epoch from(current_timestamp - block_timestamp)))::int > ?) OR (dispatch_block_timestamp IS NOT NULL AND round(extract(epoch from(dispatch_block_timestamp - block_timestamp)))::int > ?)', distance, distance
)
elsif params[:op] == 'lt'
Message.where(
Expand All @@ -52,7 +55,12 @@ def timespent
else
raise 'Invalid operator'
end
@messages_count = @messages.count

@messages = @messages.order(block_timestamp: :desc).page(params[:page]).per(25)

status = params[:status] || 'accepted,root_ready,dispatch_success,dispatch_failed'
@messages = @messages.where(status: status.split(','))
render :index
end

Expand Down

0 comments on commit 7516e13

Please sign in to comment.