mongo_clarify 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +54 -0
- data/.rspec +3 -0
- data/.rubocop.yml +20 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +100 -0
- data/Guardfile +16 -0
- data/LICENSE.txt +21 -0
- data/README.md +61 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +6 -0
- data/exe/mongo_clarify +14 -0
- data/lib/mongo_clarify/investigate.rb +41 -0
- data/lib/mongo_clarify/investigate_ruby2_7.rb +28 -0
- data/lib/mongo_clarify/output.rb +43 -0
- data/lib/mongo_clarify/version.rb +5 -0
- data/lib/mongo_clarify.rb +18 -0
- data/mongo_clarify.gemspec +28 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 36c90f7e00b8374b12af01bc1a4dccfea1e5a0794ca8de73f15f37857368acbd
|
4
|
+
data.tar.gz: d17f50a9ef3f588ee32df9a2dc072f6185e46c2e2a85f88de1795595bcd6b5f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d54511d77bba0f73c50098f3f71ca5f815a0652d0fe4ff4793bc5e7d0a1546e03f312641039243039205537ed41477ed914547dc62a166b0b1c5e55492019ded
|
7
|
+
data.tar.gz: 24d6d711bbbdb8cba7c1a2aebc1826cbb255cab637da14477eb75d6b6813ee97e04d466c9f4a4f30a45f96292074198f6553524260d0602446cdd3b0a6687308
|
data/.gitignore
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/.bundle/
|
6
|
+
/InstalledFiles
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
|
11
|
+
# rspec failure tracking
|
12
|
+
.rspec_status
|
13
|
+
|
14
|
+
# Used by dotenv library to load environment variables.
|
15
|
+
# .env
|
16
|
+
|
17
|
+
# Ignore Byebug command history file.
|
18
|
+
.byebug_history
|
19
|
+
|
20
|
+
## Specific to RubyMotion:
|
21
|
+
.dat*
|
22
|
+
.repl_history
|
23
|
+
build/
|
24
|
+
*.bridgesupport
|
25
|
+
build-iPhoneOS/
|
26
|
+
build-iPhoneSimulator/
|
27
|
+
|
28
|
+
## Specific to RubyMotion (use of CocoaPods):
|
29
|
+
#
|
30
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
31
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
32
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
33
|
+
#
|
34
|
+
# vendor/Pods/
|
35
|
+
|
36
|
+
## Documentation cache and generated files:
|
37
|
+
/.yardoc/
|
38
|
+
/_yardoc/
|
39
|
+
/doc/
|
40
|
+
/rdoc/
|
41
|
+
|
42
|
+
## Environment normalization:
|
43
|
+
/.bundle/
|
44
|
+
/vendor/bundle
|
45
|
+
/lib/bundler/man/
|
46
|
+
|
47
|
+
# for a library or gem, you might want to ignore these files since the code is
|
48
|
+
# intended to run in multiple environments; otherwise, check them in:
|
49
|
+
# Gemfile.lock
|
50
|
+
.ruby-version
|
51
|
+
.ruby-gemset
|
52
|
+
|
53
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
54
|
+
.rvmrc
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require: rubocop-performance
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
Exclude:
|
5
|
+
- "vendor/**/*"
|
6
|
+
- "spec/spec_helper.rb"
|
7
|
+
- "lib/mongo_clarify/investigate_ruby2_7.rb"
|
8
|
+
|
9
|
+
Style/Documentation:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Metrics/AbcSize:
|
13
|
+
Max: 20
|
14
|
+
|
15
|
+
Metrics/LineLength:
|
16
|
+
Max: 120
|
17
|
+
|
18
|
+
Style/LambdaCall:
|
19
|
+
Exclude:
|
20
|
+
- "lib/mongo_clarify/investigate.rb"
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at omnimani3@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
|
+
|
7
|
+
gemspec
|
8
|
+
|
9
|
+
gem 'guard-rspec'
|
10
|
+
gem 'pattern-match'
|
11
|
+
gem 'pry'
|
12
|
+
gem 'pry-byebug'
|
13
|
+
gem 'rspec'
|
14
|
+
gem 'rubocop'
|
15
|
+
gem 'rubocop-performance'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mongo_clarify (0.1.0)
|
5
|
+
pattern-match
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.0)
|
11
|
+
byebug (11.0.1)
|
12
|
+
coderay (1.1.2)
|
13
|
+
diff-lcs (1.3)
|
14
|
+
ffi (1.11.1)
|
15
|
+
formatador (0.2.5)
|
16
|
+
guard (2.15.0)
|
17
|
+
formatador (>= 0.2.4)
|
18
|
+
listen (>= 2.7, < 4.0)
|
19
|
+
lumberjack (>= 1.0.12, < 2.0)
|
20
|
+
nenv (~> 0.1)
|
21
|
+
notiffany (~> 0.0)
|
22
|
+
pry (>= 0.9.12)
|
23
|
+
shellany (~> 0.0)
|
24
|
+
thor (>= 0.18.1)
|
25
|
+
guard-compat (1.2.1)
|
26
|
+
guard-rspec (4.7.3)
|
27
|
+
guard (~> 2.1)
|
28
|
+
guard-compat (~> 1.1)
|
29
|
+
rspec (>= 2.99.0, < 4.0)
|
30
|
+
jaro_winkler (1.5.2)
|
31
|
+
listen (3.1.5)
|
32
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
33
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
34
|
+
ruby_dep (~> 1.2)
|
35
|
+
lumberjack (1.0.13)
|
36
|
+
method_source (0.9.2)
|
37
|
+
nenv (0.3.0)
|
38
|
+
notiffany (0.1.1)
|
39
|
+
nenv (~> 0.1)
|
40
|
+
shellany (~> 0.0)
|
41
|
+
parallel (1.17.0)
|
42
|
+
parser (2.6.3.0)
|
43
|
+
ast (~> 2.4.0)
|
44
|
+
pattern-match (1.0.1)
|
45
|
+
pry (0.12.2)
|
46
|
+
coderay (~> 1.1.0)
|
47
|
+
method_source (~> 0.9.0)
|
48
|
+
pry-byebug (3.7.0)
|
49
|
+
byebug (~> 11.0)
|
50
|
+
pry (~> 0.10)
|
51
|
+
rainbow (3.0.0)
|
52
|
+
rake (10.5.0)
|
53
|
+
rb-fsevent (0.10.3)
|
54
|
+
rb-inotify (0.10.0)
|
55
|
+
ffi (~> 1.0)
|
56
|
+
rspec (3.8.0)
|
57
|
+
rspec-core (~> 3.8.0)
|
58
|
+
rspec-expectations (~> 3.8.0)
|
59
|
+
rspec-mocks (~> 3.8.0)
|
60
|
+
rspec-core (3.8.0)
|
61
|
+
rspec-support (~> 3.8.0)
|
62
|
+
rspec-expectations (3.8.3)
|
63
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
64
|
+
rspec-support (~> 3.8.0)
|
65
|
+
rspec-mocks (3.8.0)
|
66
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
67
|
+
rspec-support (~> 3.8.0)
|
68
|
+
rspec-support (3.8.0)
|
69
|
+
rubocop (0.70.0)
|
70
|
+
jaro_winkler (~> 1.5.1)
|
71
|
+
parallel (~> 1.10)
|
72
|
+
parser (>= 2.6)
|
73
|
+
rainbow (>= 2.2.2, < 4.0)
|
74
|
+
ruby-progressbar (~> 1.7)
|
75
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
76
|
+
rubocop-performance (1.3.0)
|
77
|
+
rubocop (>= 0.68.0)
|
78
|
+
ruby-progressbar (1.10.0)
|
79
|
+
ruby_dep (1.5.0)
|
80
|
+
shellany (0.0.1)
|
81
|
+
thor (0.20.3)
|
82
|
+
unicode-display_width (1.6.0)
|
83
|
+
|
84
|
+
PLATFORMS
|
85
|
+
ruby
|
86
|
+
|
87
|
+
DEPENDENCIES
|
88
|
+
bundler (~> 1.16)
|
89
|
+
guard-rspec
|
90
|
+
mongo_clarify!
|
91
|
+
pattern-match
|
92
|
+
pry
|
93
|
+
pry-byebug
|
94
|
+
rake (~> 10.0)
|
95
|
+
rspec
|
96
|
+
rubocop
|
97
|
+
rubocop-performance
|
98
|
+
|
99
|
+
BUNDLED WITH
|
100
|
+
1.16.1
|
data/Guardfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
4
|
+
require 'guard/rspec/dsl'
|
5
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
6
|
+
|
7
|
+
# RSpec files
|
8
|
+
rspec = dsl.rspec
|
9
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
10
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
11
|
+
watch(rspec.spec_files)
|
12
|
+
|
13
|
+
# Ruby files
|
14
|
+
ruby = dsl.ruby
|
15
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
16
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 morihirok
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# MongoClarify
|
2
|
+
|
3
|
+
WARNING: This program is under construction.
|
4
|
+
|
5
|
+
MongoDB explain is a little hard to read because it is JSON.
|
6
|
+
|
7
|
+
This program makes it possible to convert MongoDB explain into Markdown table format. As below.
|
8
|
+
|
9
|
+
| Key | Value |
|
10
|
+
| --- | --- |
|
11
|
+
| Means of Operation | Collection Scan |
|
12
|
+
| nReturned | 1 |
|
13
|
+
| executionTimeMillis | 59 msec |
|
14
|
+
| totalKeysExamined | 0 |
|
15
|
+
| totalDocsExamined | 100000 |
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'mongo_clarify'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install mongo_clarify
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
In the case of CLI.
|
34
|
+
|
35
|
+
```sh
|
36
|
+
$ mongo_clarify <Json file of MongoDB explain>
|
37
|
+
```
|
38
|
+
|
39
|
+
If you are using Mongoid.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
MongoClarify.run(Model.where(query).explain)
|
43
|
+
```
|
44
|
+
|
45
|
+
## Development
|
46
|
+
|
47
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
48
|
+
|
49
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mongo_clarify. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
54
|
+
|
55
|
+
## License
|
56
|
+
|
57
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
58
|
+
|
59
|
+
## Code of Conduct
|
60
|
+
|
61
|
+
Everyone interacting in the MongoClarify project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/mongo_clarify/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'mongo_clarify'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/mongo_clarify
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift("#{__dir__}/../lib")
|
5
|
+
|
6
|
+
require 'JSON'
|
7
|
+
require 'mongo_clarify'
|
8
|
+
|
9
|
+
raise ArgumentError, 'Please input explain json.' if ARGV[0].nil?
|
10
|
+
|
11
|
+
file = File.read("./#{ARGV[0]}")
|
12
|
+
explain = JSON.parse(file, symbolize_names: true)
|
13
|
+
|
14
|
+
MongoClarify.run(explain)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pattern-match/experimental'
|
4
|
+
|
5
|
+
module MongoClarify
|
6
|
+
class Investigate
|
7
|
+
using PatternMatch
|
8
|
+
|
9
|
+
def initialize(explain)
|
10
|
+
@explain = explain
|
11
|
+
end
|
12
|
+
|
13
|
+
def operation_method
|
14
|
+
match(@explain) do
|
15
|
+
with(Hash.(queryPlanner: Hash.(winningPlan: Hash.(stage: 'COLLSCAN')))) do
|
16
|
+
'Collection Scan'
|
17
|
+
end
|
18
|
+
with(Hash.(queryPlanner: Hash.(winningPlan: Hash.(stage: 'FETCH', inputStage: Hash.(stage: 'IXSCAN', indexName: index_name))))) do
|
19
|
+
"Index Scan (Index Name: #{index_name})"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
rescue PatternMatch::NoMatchingPatternError
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def execution_stats
|
27
|
+
match(@explain) do
|
28
|
+
with(Hash.(executionStats: Hash.(nReturned: n, executionTimeMillis: msec, totalKeysExamined: keys, totalDocsExamined: docs))) do
|
29
|
+
{
|
30
|
+
n_returned: n,
|
31
|
+
execution_time_millis: msec,
|
32
|
+
total_keys_examined: keys,
|
33
|
+
total_docs_examined: docs
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
rescue PatternMatch::NoMatchingPatternError
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MongoClarify
|
4
|
+
class InvestigateRuby2_7
|
5
|
+
def initialize(explain)
|
6
|
+
@explain = explain
|
7
|
+
end
|
8
|
+
|
9
|
+
def operation_method
|
10
|
+
case @explain
|
11
|
+
in { queryPlanner: { winningPlan: { stage: 'COLLSCAN' } } }
|
12
|
+
'Collection Scan'
|
13
|
+
in { queryPlanner: { winningPlan: { stage: 'FETCH', inputStage: { stage: 'IXSCAN', indexName: index_name } } } }
|
14
|
+
"Index Scan (Index Name: #{index_name})"
|
15
|
+
else
|
16
|
+
'Unknown'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def execution_stats
|
21
|
+
case @explain
|
22
|
+
in { executionStats: { nReturned: n, executionTimeMillis: msec, totalKeysExamined: keys, totalDocsExamined: docs } }
|
23
|
+
else
|
24
|
+
end
|
25
|
+
{ n_returned: n, execution_time_millis: msec, total_keys_examined: keys, total_docs_examined: docs }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MongoClarify
|
4
|
+
class Output
|
5
|
+
def initialize(operation_method, exec_stats)
|
6
|
+
@operation_method = operation_method
|
7
|
+
@exec_stats = exec_stats
|
8
|
+
end
|
9
|
+
|
10
|
+
def markdown_table
|
11
|
+
if @operation_method.nil? && @exec_stats.nil?
|
12
|
+
return puts 'Could not parse this explain...'
|
13
|
+
elsif @exec_stats.nil?
|
14
|
+
return puts means_of_operation_only_table(@operation_method)
|
15
|
+
end
|
16
|
+
|
17
|
+
puts full_table
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def full_table
|
23
|
+
<<~EXPLAIN
|
24
|
+
| Key | Value |
|
25
|
+
| --- | --- |
|
26
|
+
| Means of Operation | #{@operation_method || 'Unknown'} |
|
27
|
+
| nReturned | #{@exec_stats[:n_returned]} |
|
28
|
+
| executionTimeMillis | #{@exec_stats[:execution_time_millis]} msec |
|
29
|
+
| totalKeysExamined | #{@exec_stats[:total_keys_examined]} |
|
30
|
+
| totalDocsExamined | #{@exec_stats[:total_docs_examined]} |
|
31
|
+
EXPLAIN
|
32
|
+
end
|
33
|
+
|
34
|
+
def means_of_operation_only_table(operation_method)
|
35
|
+
<<~EXPLAIN
|
36
|
+
| Key | Value |
|
37
|
+
| --- | --- |
|
38
|
+
| Means of Operation | #{operation_method} |
|
39
|
+
| Execution Stats | Not detected |
|
40
|
+
EXPLAIN
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mongo_clarify/version'
|
4
|
+
|
5
|
+
require_relative 'mongo_clarify/investigate'
|
6
|
+
require_relative 'mongo_clarify/output'
|
7
|
+
|
8
|
+
module MongoClarify
|
9
|
+
class << self
|
10
|
+
def run(explain)
|
11
|
+
investigate = MongoClarify::Investigate.new(explain)
|
12
|
+
exec_stats = investigate.execution_stats
|
13
|
+
operation_method = investigate.operation_method
|
14
|
+
|
15
|
+
MongoClarify::Output.new(operation_method, exec_stats).markdown_table
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'mongo_clarify/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'mongo_clarify'
|
9
|
+
spec.version = MongoClarify::VERSION
|
10
|
+
spec.authors = ['morihirok']
|
11
|
+
spec.email = ['omnimani3@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = "Make MongoDB's explain results more understandable."
|
14
|
+
spec.homepage = 'https://github.com/morihirok/mongo-clarify'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_dependency 'pattern-match'
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongo_clarify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- morihirok
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pattern-match
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- omnimani3@gmail.com
|
72
|
+
executables:
|
73
|
+
- mongo_clarify
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".rubocop.yml"
|
80
|
+
- ".travis.yml"
|
81
|
+
- CODE_OF_CONDUCT.md
|
82
|
+
- Gemfile
|
83
|
+
- Gemfile.lock
|
84
|
+
- Guardfile
|
85
|
+
- LICENSE.txt
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- bin/console
|
89
|
+
- bin/setup
|
90
|
+
- exe/mongo_clarify
|
91
|
+
- lib/mongo_clarify.rb
|
92
|
+
- lib/mongo_clarify/investigate.rb
|
93
|
+
- lib/mongo_clarify/investigate_ruby2_7.rb
|
94
|
+
- lib/mongo_clarify/output.rb
|
95
|
+
- lib/mongo_clarify/version.rb
|
96
|
+
- mongo_clarify.gemspec
|
97
|
+
homepage: https://github.com/morihirok/mongo-clarify
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.7.6
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: Make MongoDB's explain results more understandable.
|
121
|
+
test_files: []
|