.vbw-planning/milestones/07-rails-audit-and-refactoring/03-controller-route-refactoring/03-PLAN.md
Reduce SourcesController complexity by extracting word count average queries into the existing SourcesIndexMetrics object (C4), and moving redirect validation to the ParameterSanitizer service (C10).
app/controllers/source_monitor/sources_controller.rb:50-62 computes @avg_feed_word_counts and @avg_scraped_word_counts inlineSourceMonitor::Analytics::SourcesIndexMetrics already exists and handles other index metrics -- word count averages belong theresafe_redirect_path (lines 171-176) is a pure function that validates redirect paths -- belongs in SourceMonitor::Security::ParameterSanitizerlib/source_monitor/security/parameter_sanitizer.rb already has sanitize methodAdd tests to the existing ParameterSanitizer test file:
In lib/source_monitor/security/parameter_sanitizer.rb, add class method:
def self.safe_redirect_path(raw_value)
return if raw_value.blank?
sanitized = sanitize(raw_value.to_s)
sanitized.start_with?("/") ? sanitized : nil
end
Add word_count_averages(source_ids) method to SourceMonitor::Analytics::SourcesIndexMetrics that returns a hash with :feed and :scraped keys. Update SourcesController#index to call metrics.word_count_averages(source_ids) and assign the instance variables from the result.
safe_redirect_path private method with SourceMonitor::Security::ParameterSanitizer.safe_redirect_pathsafe_redirect_path private methodbin/rails test -- all passbin/rubocop -- zero offenses