Class: Rack::MiniProfiler::AbstractStore

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_profiler/storage/abstract_store.rb

Direct Known Subclasses

FileStore, MemcacheStore, MemoryStore, RedisStore

Constant Summary collapse

MAX_TOKEN_AGE =

maximum age of allowed tokens before cycling in seconds

1800

Instance Method Summary collapse

Instance Method Details

#allowed_tokensObject

a list of tokens that are permitted to access profiler in explicit mode

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/mini_profiler/storage/abstract_store.rb', line 40

def allowed_tokens
  raise NotImplementedError.new("allowed_tokens is not implemented")
end

#diagnostics(user) ⇒ Object



34
35
36
37
# File 'lib/mini_profiler/storage/abstract_store.rb', line 34

def diagnostics(user)
  # this is opt in, no need to explode if not implemented
  ""
end

#fetch_snapshots_group(group_name) ⇒ Array<Rack::MiniProfiler::TimerStruct::Page>

Returns list of snapshots of the group. Blank array if the group doesn’t exist.

Parameters:

  • group_name (String)

Returns:

Raises:

  • (NotImplementedError)


63
64
65
# File 'lib/mini_profiler/storage/abstract_store.rb', line 63

def fetch_snapshots_group(group_name)
  raise NotImplementedError.new("fetch_snapshots_group is not implemented")
end

#fetch_snapshots_overviewObject

returns a hash where the keys are group names and the values are hashes that contain 3 keys:

1. `:worst_score` => the duration of the worst/slowest snapshot in the group (float)
2. `:best_score` => the duration of the best/fastest snapshot in the group (float)
3. `:snapshots_count` => the number of snapshots in the group (integer)

Raises:

  • (NotImplementedError)


57
58
59
# File 'lib/mini_profiler/storage/abstract_store.rb', line 57

def fetch_snapshots_overview
  raise NotImplementedError.new("fetch_snapshots_overview is not implemented")
end

#get_unviewed_ids(user) ⇒ Object

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/mini_profiler/storage/abstract_store.rb', line 30

def get_unviewed_ids(user)
  raise NotImplementedError.new("get_unviewed_ids is not implemented")
end

#load(id) ⇒ Object

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/mini_profiler/storage/abstract_store.rb', line 14

def load(id)
  raise NotImplementedError.new("load is not implemented")
end

#load_snapshot(id, group_name) ⇒ Object

Raises:

  • (NotImplementedError)


67
68
69
# File 'lib/mini_profiler/storage/abstract_store.rb', line 67

def load_snapshot(id, group_name)
  raise NotImplementedError.new("load_snapshot is not implemented")
end

#push_snapshot(page_struct, group_name, config) ⇒ Object

Raises:

  • (NotImplementedError)


48
49
50
# File 'lib/mini_profiler/storage/abstract_store.rb', line 48

def push_snapshot(page_struct, group_name, config)
  raise NotImplementedError.new("push_snapshot is not implemented")
end

#save(page_struct) ⇒ Object

Raises:

  • (NotImplementedError)


10
11
12
# File 'lib/mini_profiler/storage/abstract_store.rb', line 10

def save(page_struct)
  raise NotImplementedError.new("save is not implemented")
end

#set_all_unviewed(user, ids) ⇒ Object

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/mini_profiler/storage/abstract_store.rb', line 26

def set_all_unviewed(user, ids)
  raise NotImplementedError.new("set_all_unviewed is not implemented")
end

#set_unviewed(user, id) ⇒ Object

Raises:

  • (NotImplementedError)


18
19
20
# File 'lib/mini_profiler/storage/abstract_store.rb', line 18

def set_unviewed(user, id)
  raise NotImplementedError.new("set_unviewed is not implemented")
end

#set_viewed(user, id) ⇒ Object

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/mini_profiler/storage/abstract_store.rb', line 22

def set_viewed(user, id)
  raise NotImplementedError.new("set_viewed is not implemented")
end

#should_take_snapshot?(period) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


44
45
46
# File 'lib/mini_profiler/storage/abstract_store.rb', line 44

def should_take_snapshot?(period)
  raise NotImplementedError.new("should_take_snapshot? is not implemented")
end

#snapshots_group(group_name) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/mini_profiler/storage/abstract_store.rb', line 79

def snapshots_group(group_name)
  snapshots = fetch_snapshots_group(group_name)
  data = []
  snapshots.each do |snapshot|
    data << {
      id: snapshot[:id],
      duration: snapshot.duration_ms,
      sql_count: snapshot[:sql_count],
      timestamp: snapshot[:started_at],
      custom_fields: snapshot[:custom_fields]
    }
  end
  data.sort_by! { |s| s[:duration] }
  data.reverse!
  data
end

#snapshots_overviewObject



71
72
73
74
75
76
77
# File 'lib/mini_profiler/storage/abstract_store.rb', line 71

def snapshots_overview
  groups = fetch_snapshots_overview.to_a
  groups.sort_by! { |name, hash| hash[:worst_score] }
  groups.reverse!
  groups.map! { |name, hash| hash.merge(name: name) }
  groups
end