47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/mongo_profiler/models/profile.rb', line 47
def register(started_at, database, collection, selector, options = {})
return if collection =~ /mongo_profiler/ || collection =~ /system/
return if selector['$explain']
_caller = MongoProfiler::Caller.new(caller)
group = ProfileGroup.find_or_create_by(name: MongoProfiler.current_group_name)
group.touch
profile_md5 = generate_profile_md5(database, collection, selector, _caller)
return if Profile.where(profile_md5: profile_md5, profile_group_id: group.id).any?
result = {}
result[:profile_md5] = profile_md5
result[:profile_group_id] = group.id
result[:total_time] = elapsed(started_at)
result[:command_database] = database
result[:command_collection] = collection
result[:command] = JSON.dump(selector)
result[:file] = _caller.file
result[:line] = _caller.line
result[:method] = _caller.method
result[:explain] = JSON.dump(generate_explain(collection, selector))
self.create(result)
end
|