Class: SlimScrooge::Callsites
- Inherits:
-
Object
- Object
- SlimScrooge::Callsites
- Defined in:
- lib/slim_scrooge/callsites.rb
Overview
Contains the complete list of callsites
Constant Summary collapse
- CallsitesMutex =
Mutex.new
- ScroogeCallsiteSample =
1..16
- @@callsites =
{}
Class Method Summary collapse
-
.[](callsite_key) ⇒ Object
Return the callsite for this key.
-
.add_callsite(callsite_key, callsite) ⇒ Object
Add a new callsite, wrap in a mutex for safety.
-
.add_seen_column(callsite, seen_column) ⇒ Object
Record that a column was accessed, wrap in a mutex for safety.
-
.callsite_key(sql) ⇒ Object
Generate a key string - uses the portion of the query before the WHERE together with the callsite_hash generated by callsite_hash.c.
-
.create(sql, callsite_key, name) ⇒ Object
Create a new callsite.
-
.has_key?(callsite_key) ⇒ Boolean
Whether we have encountered a callsite before.
Class Method Details
.[](callsite_key) ⇒ Object
Return the callsite for this key
20 21 22 |
# File 'lib/slim_scrooge/callsites.rb', line 20 def [](callsite_key) @@callsites[callsite_key] end |
.add_callsite(callsite_key, callsite) ⇒ Object
Add a new callsite, wrap in a mutex for safety
55 56 57 58 59 |
# File 'lib/slim_scrooge/callsites.rb', line 55 def add_callsite(callsite_key, callsite) CallsitesMutex.synchronize do @@callsites[callsite_key] = callsite end end |
.add_seen_column(callsite, seen_column) ⇒ Object
Record that a column was accessed, wrap in a mutex for safety
63 64 65 66 67 |
# File 'lib/slim_scrooge/callsites.rb', line 63 def add_seen_column(callsite, seen_column) CallsitesMutex.synchronize do callsite.seen_columns << seen_column end end |
.callsite_key(sql) ⇒ Object
Generate a key string - uses the portion of the query before the WHERE together with the callsite_hash generated by callsite_hash.c
37 38 39 |
# File 'lib/slim_scrooge/callsites.rb', line 37 def callsite_key(sql) callsite_hash + sql.gsub(/\sWHERE.*/i, "").hash end |
.create(sql, callsite_key, name) ⇒ Object
Create a new callsite
43 44 45 46 47 48 49 50 51 |
# File 'lib/slim_scrooge/callsites.rb', line 43 def create(sql, callsite_key, name) begin model_class = name.split.first.constantize rescue NameError, NoMethodError add_callsite(callsite_key, nil) else add_callsite(callsite_key, Callsite.make_callsite(model_class, sql)) end end |
.has_key?(callsite_key) ⇒ Boolean
Whether we have encountered a callsite before
14 15 16 |
# File 'lib/slim_scrooge/callsites.rb', line 14 def has_key?(callsite_key) @@callsites.has_key?(callsite_key) end |