Class: RailsPulse::Suggestions::ViewSuggestionsService

Inherits:
Base
  • Object
show all
Defined in:
app/services/rails_pulse/suggestions/view_suggestions_service.rb

Instance Attribute Summary

Attributes inherited from Base

#operation, #parent

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from RailsPulse::Suggestions::Base

Instance Method Details

#generateObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/services/rails_pulse/suggestions/view_suggestions_service.rb', line 4

def generate
  suggestions = []

  if operation.duration > 100
    suggestions << build_suggestion(
      type: "performance",
      icon: "zap",
      title: "Slow View Rendering",
      description: "This view took #{operation.duration.round(2)}ms to render. Consider fragment caching or reducing database calls.",
      priority: "high"
    )
  end

  # Check for database queries in views
  if parent
    view_db_operations = parent.operations
      .where(operation_type: [ "sql" ])
      .where("occurred_at >= ? AND occurred_at <= ?",
             operation.occurred_at,
             operation.occurred_at + operation.duration)

    if view_db_operations.count > 0
      suggestions << build_suggestion(
        type: "database",
        icon: "database",
        title: "Database Queries in View",
        description: "#{view_db_operations.count} database queries during view rendering. Move data fetching to the controller.",
        priority: "medium"
      )
    end
  end

  suggestions
end