Replies: 2 comments
-
|
This would be a useful feature to have. Should be done as a block |
Beta Was this translation helpful? Give feedback.
-
|
@KieranP this is a great idea! I've opened https://jira.mongodb.org/browse/MONGOID-5903 to capture this as a feature request. I'm sure you could accomplish something similar as follows - though this might not be the best approach (which is why I opened the feature request 😄) # config/initializers/mongoid_callsite_comment.rb
module MongoidCallsiteComment
def execute(connection, context:, options: {})
# Duplicate the spec so we don't mutate driver internals in place
spec = @spec.dup
loc = caller_locations.first
spec[:comment] ||= loc.to_s if spec.is_a?(Hash)
# Swap the spec for this execution only
orig_spec = @spec
@spec= spec
super
ensure
@spec= orig_spec
end
end
begin
require "mongo"
Mongo::Operation::Executable.prepend(MongoidCallsiteComment)
rescue NameError
# If driver loads late in your boot order, defer until it’s loaded.
ActiveSupport.on_load(:mongoid) do
Mongo::Operation::Executable.prepend(MongoidCallsiteComment)
end
endA quick test will produce results such as the following (assuming the slow query threshold is low enough to log the operation):
If this is in a Rails app the caller info should be more reflective of where the operation originated (I just did this in IRB). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to debug some performance issues with our MongoDB Atlas database.
The performance advisor is good at suggesting indexes, but it doesn't have context to show us where the query was run from.
After a bit of research, it does appear that we can add a comment to queries on a individual basis:
What I am looking for is a way to set this for ALL queries made during a Rails request. e.g.
The idea being that all queries will be commented with the URL path they were executed on, helping us pinpoint where the query ran so that we can change the underlying query when indexes can't help.
Does Mongoid have such a thing?
If not, would such a thing be possible to achieve?
If so, would such a thing be considered for development?
If not, what would others recommend?
Thanks :-)
Beta Was this translation helpful? Give feedback.
All reactions