Sha256: 4c0bc564b753b6d507e56cfbba4c2e6fd756e290a58ca748e87fb96a1a23178f
Contents?: true
Size: 1.48 KB
Versions: 17
Compression:
Stored size: 1.48 KB
Contents
# mongo_mapper patches # TODO: Include overrides for distinct, update, cursor, and create class Plucky::Query alias_method :find_each_without_profiling, :find_each alias_method :find_one_without_profiling, :find_one alias_method :count_without_profiling, :count alias_method :remove_without_profiling, :remove def find_each(*args, &blk) return profile_database_operation(__callee__, filtered_inspect(), *args, &blk) end def find_one(*args, &blk) return profile_database_operation(__callee__, filtered_inspect(args[0]), *args, &blk) end def count(*args, &blk) return profile_database_operation(__callee__, filtered_inspect(), *args, &blk) end def remove(*args, &blk) return profile_database_operation(__callee__, filtered_inspect(), *args, &blk) end private def profile_database_operation(method, message, *args, &blk) return self.send("#{method.id2name}_without_profiling", *args, &blk) unless SqlPatches.should_measure? start = Time.now result = self.send("#{method.id2name}_without_profiling", *args, &blk) elapsed_time = SqlPatches.elapsed_time(start) query_message = "#{@collection.name}.#{method.id2name} => #{message}" ::Rack::MiniProfiler.record_sql(query_message, elapsed_time) result end def filtered_inspect(hash = to_hash()) hash_string = hash.reject { |key| key == :transformer }.collect do |key, value| " #{key}: #{value.inspect}" end.join(",\n") "{\n#{hash_string}\n}" end end
Version data entries
17 entries across 17 versions & 2 rubygems