suggest-db-indices 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +5 -19
- data/lib/{suggest_db_indices.rb → suggest-db-indices.rb} +3 -1
- data/lib/suggest_db_indices/clojure.rb +23 -0
- data/lib/suggest_db_indices/core.rb +1 -1
- data/lib/suggest_db_indices/railtie.rb +7 -0
- data/lib/suggest_db_indices/version.rb +1 -1
- data/lib/tasks/suggest_db_indices.rake +4 -0
- data/suggest_db_indices.gemspec +2 -2
- metadata +14 -14
- data/lib/suggest_db_indices/clojurian_imperialism.rb +0 -16
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Suggest-Db-Indices
|
2
2
|
|
3
|
-
A gem for your rails project that suggests indices for you to add in your database.
|
3
|
+
A gem for your rails project that suggests indices for you to add in your database. It looks for unindexed foreign keys, and what columns actually get queried.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -12,24 +12,10 @@ And then execute:
|
|
12
12
|
|
13
13
|
$ bundle
|
14
14
|
|
15
|
-
Or install it yourself as:
|
16
|
-
|
17
|
-
$ gem install suggest-db-indices
|
18
|
-
|
19
15
|
## Usage
|
20
16
|
|
21
|
-
|
22
|
-
2. require 'suggest_db_indices'
|
23
|
-
3. SuggestDbIndices.go!
|
24
|
-
|
25
|
-
## Contributing
|
26
|
-
|
27
|
-
1. Fork it
|
28
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
30
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
-
5. Create new Pull Request
|
17
|
+
bundle exec rake suggest_db_indices
|
32
18
|
|
33
|
-
##
|
34
|
-
1.
|
35
|
-
|
19
|
+
## Changes
|
20
|
+
0.1.0 (July 8, 2012) - Added the rake task.
|
21
|
+
0.0.3 (July 4, 2012) - Added justification for each index added, made log file handling more robust
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'tempfile'
|
2
|
+
require 'rails'
|
2
3
|
require 'rails/generators'
|
3
4
|
|
4
5
|
require File.join File.dirname(__FILE__), '/suggest_db_indices/version'
|
5
|
-
require File.join File.dirname(__FILE__), '/suggest_db_indices/
|
6
|
+
require File.join File.dirname(__FILE__), '/suggest_db_indices/clojure'
|
6
7
|
require File.join File.dirname(__FILE__), '/suggest_db_indices/core'
|
8
|
+
require File.join File.dirname(__FILE__), '/suggest_db_indices/railtie'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module SuggestDbIndices
|
2
|
+
# Learnings from Clojure for make great benefit ruby
|
3
|
+
module Clojure
|
4
|
+
class << self
|
5
|
+
# Get multiple keys, e.g.,
|
6
|
+
# h = {:b => {:a => 5}}
|
7
|
+
# Clojure.get_in(h, [:b, :a]) # => 5
|
8
|
+
# Clojure.get_in(h, [:b, :a, :c]) # => nil
|
9
|
+
# Clojure.get_in(h, [:b, :a, :c], 1) # => 1
|
10
|
+
def get_in enumerable, keys, default = nil
|
11
|
+
current = enumerable
|
12
|
+
while key = keys.shift
|
13
|
+
unless current.is_a? Enumerable
|
14
|
+
current = nil
|
15
|
+
break
|
16
|
+
end
|
17
|
+
current = current[key]
|
18
|
+
end
|
19
|
+
current || default
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -176,7 +176,7 @@ module SuggestDbIndices
|
|
176
176
|
if non_pk_columns_by_table[current_table] && non_pk_columns_by_table[current_table].include?(column_candidate)
|
177
177
|
# We only care about the identifiers that match up to a table and column.
|
178
178
|
# This is a ghetto way to to avoid having to parse SQL (extremely difficult)
|
179
|
-
if
|
179
|
+
if Clojure.get_in queried_columns_by_table, [current_table, column_candidate]
|
180
180
|
queried_columns_by_table[current_table][column_candidate] += 1
|
181
181
|
else
|
182
182
|
queried_columns_by_table[current_table] = {column_candidate => 1}
|
data/suggest_db_indices.gemspec
CHANGED
@@ -4,8 +4,8 @@ require File.join File.dirname(__FILE__), 'lib/suggest_db_indices/version'
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Isak Sky"]
|
6
6
|
gem.email = ["isak.sky@gmail.com"]
|
7
|
-
gem.description =
|
8
|
-
gem.summary =
|
7
|
+
gem.description = "A gem for rails projects that suggests indices to add to the database."
|
8
|
+
gem.summary = "A gem for rails projects that suggests indices to add to the database."
|
9
9
|
gem.homepage = "https://github.com/isaksky/suggest-db-indices"
|
10
10
|
gem.license = "MIT"
|
11
11
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: suggest-db-indices
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &2162432420 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2162432420
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: awesome_print
|
27
|
-
requirement: &
|
27
|
+
requirement: &2162431840 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2162431840
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: pry
|
38
|
-
requirement: &
|
38
|
+
requirement: &2162431160 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,9 +43,8 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
47
|
-
description: A gem for
|
48
|
-
your database. Currently it suggests adding indices to unindexed foreign key columns.
|
46
|
+
version_requirements: *2162431160
|
47
|
+
description: A gem for rails projects that suggests indices to add to the database.
|
49
48
|
email:
|
50
49
|
- isak.sky@gmail.com
|
51
50
|
executables: []
|
@@ -57,10 +56,12 @@ files:
|
|
57
56
|
- LICENSE
|
58
57
|
- README.md
|
59
58
|
- Rakefile
|
60
|
-
- lib/
|
61
|
-
- lib/suggest_db_indices/
|
59
|
+
- lib/suggest-db-indices.rb
|
60
|
+
- lib/suggest_db_indices/clojure.rb
|
62
61
|
- lib/suggest_db_indices/core.rb
|
62
|
+
- lib/suggest_db_indices/railtie.rb
|
63
63
|
- lib/suggest_db_indices/version.rb
|
64
|
+
- lib/tasks/suggest_db_indices.rake
|
64
65
|
- suggest_db_indices.gemspec
|
65
66
|
homepage: https://github.com/isaksky/suggest-db-indices
|
66
67
|
licenses:
|
@@ -86,6 +87,5 @@ rubyforge_project:
|
|
86
87
|
rubygems_version: 1.8.11
|
87
88
|
signing_key:
|
88
89
|
specification_version: 3
|
89
|
-
summary: A gem for
|
90
|
-
database.
|
90
|
+
summary: A gem for rails projects that suggests indices to add to the database.
|
91
91
|
test_files: []
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# Learnings from Clojure for make great benefit ruby
|
2
|
-
|
3
|
-
module Enumerable
|
4
|
-
# E.g., {:foo => {:bar => 5}}.get_in(:foo, :bar) #=> 5
|
5
|
-
def get_in keys, default = nil
|
6
|
-
v = self[keys.first]
|
7
|
-
rest = keys.drop 1
|
8
|
-
if rest.any?
|
9
|
-
v.get_in rest, default
|
10
|
-
else
|
11
|
-
v ? v : default
|
12
|
-
end
|
13
|
-
rescue NoMethodError => ex
|
14
|
-
default
|
15
|
-
end
|
16
|
-
end
|