- Add comprehensive file information display (content type, size, dimensions) - Move complex image dimension logic from views to TelegramBotLogsHelper - Add percentage calculations to performance metrics section - Use Rails associations instead of manual BlobFile lookups - Update slow requests filtering to use total_request_time column - Enhance search result thumbnails and improve post linking - Add comprehensive test coverage for helper methods - Improve error handling and type safety throughout
104 lines
2.7 KiB
Ruby
104 lines
2.7 KiB
Ruby
# typed: false
|
|
class TelegramBotLogsController < ApplicationController
|
|
before_action :set_telegram_bot_log, only: %i[show]
|
|
after_action :verify_authorized
|
|
|
|
def index
|
|
authorize TelegramBotLog
|
|
|
|
# Start with policy scope
|
|
@telegram_bot_logs = policy_scope(TelegramBotLog)
|
|
|
|
# Apply filters
|
|
@telegram_bot_logs = apply_filters(@telegram_bot_logs)
|
|
|
|
# Order by most recent first
|
|
@telegram_bot_logs = @telegram_bot_logs.recent
|
|
|
|
# Paginate with Kaminari
|
|
@limit = (params[:limit] || 50).to_i.clamp(1, 500)
|
|
@telegram_bot_logs = @telegram_bot_logs.page(params[:page]).per(@limit)
|
|
|
|
# Load associations for display
|
|
@telegram_bot_logs = @telegram_bot_logs.includes(:processed_image)
|
|
|
|
# Set up filter options for the view
|
|
@status_options = TelegramBotLog.statuses.keys
|
|
@filter_params =
|
|
params.slice(
|
|
:telegram_user_id,
|
|
:status,
|
|
:start_date,
|
|
:end_date,
|
|
:min_results,
|
|
:max_results,
|
|
:slow_requests,
|
|
)
|
|
end
|
|
|
|
def show
|
|
authorize @telegram_bot_log
|
|
|
|
# The processed_image association will be loaded automatically when accessed
|
|
end
|
|
|
|
private
|
|
|
|
def set_telegram_bot_log
|
|
@telegram_bot_log =
|
|
TelegramBotLog.includes(:processed_image).find(params[:id])
|
|
rescue ActiveRecord::RecordNotFound
|
|
redirect_to telegram_bot_logs_path, alert: "Telegram bot log not found."
|
|
end
|
|
|
|
def apply_filters(scope)
|
|
# Filter by telegram user ID
|
|
if params[:telegram_user_id].present?
|
|
scope = scope.for_user(params[:telegram_user_id].to_i)
|
|
end
|
|
|
|
# Filter by status
|
|
if params[:status].present? && TelegramBotLog.statuses.key?(params[:status])
|
|
scope = scope.where(status: params[:status])
|
|
end
|
|
|
|
# Filter by date range
|
|
if params[:start_date].present?
|
|
begin
|
|
start_date = Date.parse(params[:start_date])
|
|
scope =
|
|
scope.where("request_timestamp >= ?", start_date.beginning_of_day)
|
|
rescue Date::Error
|
|
# Ignore invalid date
|
|
end
|
|
end
|
|
|
|
if params[:end_date].present?
|
|
begin
|
|
end_date = Date.parse(params[:end_date])
|
|
scope = scope.where("request_timestamp <= ?", end_date.end_of_day)
|
|
rescue Date::Error
|
|
# Ignore invalid date
|
|
end
|
|
end
|
|
|
|
# Filter by search results count
|
|
if params[:min_results].present?
|
|
scope =
|
|
scope.where("search_results_count >= ?", params[:min_results].to_i)
|
|
end
|
|
|
|
if params[:max_results].present?
|
|
scope =
|
|
scope.where("search_results_count <= ?", params[:max_results].to_i)
|
|
end
|
|
|
|
# Filter by performance metrics
|
|
if params[:slow_requests].present? && params[:slow_requests] == "true"
|
|
scope = scope.slow_requests
|
|
end
|
|
|
|
scope
|
|
end
|
|
end
|